-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathencryption.php
52 lines (46 loc) · 1.35 KB
/
encryption.php
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
42
43
44
45
46
47
48
49
50
51
52
<?php
use Spray\Serializer\AnnotationBackedPropertyInfo;
use Spray\Serializer\Cache\ArrayCache;
use Spray\Serializer\Encryption\EncryptorGenerator;
use Spray\Serializer\Encryption\EncryptorLocator;
use Spray\Serializer\EncryptionListener;
use Spray\Serializer\Object\ObjectSerializerGenerator;
use Spray\Serializer\Object\SerializerLocator;
use Spray\Serializer\Object\SerializerRegistry;
use Spray\Serializer\ObjectListener;
use Spray\Serializer\Serializer;
use Zend\Crypt\BlockCipher;
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
$blockCipher = BlockCipher::factory('mcrypt', ['algo' => 'aes']);
$blockCipher->setKey('5eDCZRmyX8s7nbgV9f6pVrmRISdc5t8L');
$serializer = new Serializer();
$serializer->attach(
new EncryptionListener(
new EncryptorLocator(
new EncryptorGenerator(new AnnotationBackedPropertyInfo()),
new ArrayCache('Encryptor')
),
$blockCipher
)
);
$serializer->attach(
new ObjectListener(
new SerializerLocator(
new SerializerRegistry(),
new ObjectSerializerGenerator(
new AnnotationBackedPropertyInfo()
),
new ArrayCache('Serializer')
)
)
);
var_export($serializer->serialize(new EncryptMe()));
class EncryptMe
{
/**
* @var string
* @private
*/
private $secret = 'I\'m secret';
}