1 | <?php |
||
10 | trait CryptTrait |
||
11 | { |
||
12 | private $key; |
||
13 | private $authentication; |
||
14 | |||
15 | /** |
||
16 | * Set the keys to encrypt and authenticate. |
||
17 | * |
||
18 | * @param string $key |
||
19 | * |
||
20 | * @return self |
||
21 | */ |
||
22 | public function key($key) |
||
23 | { |
||
24 | $this->key = self::hkdf($key, 'KeyForEncryption'); |
||
25 | $this->authentication = self::hkdf($key, 'KeyForAuthentication'); |
||
26 | |||
27 | return $this; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Encrypt the given value. |
||
32 | * |
||
33 | * @param string $value |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | private function encrypt($value) |
||
49 | |||
50 | /** |
||
51 | * Decrypt the given value. |
||
52 | * |
||
53 | * @param string $value |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | private function decrypt($value) |
||
75 | |||
76 | /** |
||
77 | * Get derived key |
||
78 | * http://tools.ietf.org/html/rfc5869. |
||
79 | * |
||
80 | * @param string $ikm Initial Keying Material |
||
81 | * @param string $info What sort of key are we deriving? |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | private static function hkdf($ikm, $info = '') |
||
100 | } |
||
101 |