-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple.php
More file actions
41 lines (29 loc) · 1.04 KB
/
simple.php
File metadata and controls
41 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/** @noinspection DuplicatedCode */
use Hobocta\Encrypt\Encryptor\Fabric\EncryptorFabric;
use Hobocta\Encrypt\EncryptService;
use Hobocta\Encrypt\Exception\EncryptException;
use Hobocta\Encrypt\Stringify\Base64Stringify;
require __DIR__ . '/../vendor/autoload.php';
$data = 'My secret data!';
$password = '1234';
try {
$key = sha1($password);
$encryptorFabric = new EncryptorFabric($key);
$encryptService = new EncryptService($encryptorFabric->createEncryptor128(), new Base64Stringify());
} catch (EncryptException $e) {
exit(sprintf(
'%s: %s at %s:%s%s',
get_class($e),
$e->getMessage(),
$e->getFile(),
$e->getLine(),
PHP_EOL
));
}
echo 'Data: ' . var_export($data, true) . PHP_EOL;
$encrypted = $encryptService->encrypt($data);
echo 'Encrypted: ' . var_export($encrypted, true) . PHP_EOL;
$decrypted = $encryptService->decrypt($encrypted);
echo 'Decrypted: ' . var_export($decrypted, true) . PHP_EOL;
echo 'Result: ' . ($data === $decrypted ? 'Equals' : 'Failure') . PHP_EOL;