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 The binary key |
||
19 | * |
||
20 | * @return self |
||
21 | */ |
||
22 | public function key($key) |
||
29 | |||
30 | /** |
||
31 | * Encrypt the given value. |
||
32 | * |
||
33 | * @param string $value |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | private function encrypt($value) |
||
47 | |||
48 | /** |
||
49 | * Decrypt the given value. |
||
50 | * |
||
51 | * @param string $value |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | private function decrypt($value) |
||
71 | |||
72 | /** |
||
73 | * Check whether the key exists or not. |
||
74 | * |
||
75 | * @throws RuntimeException |
||
76 | */ |
||
77 | private function checkKey() |
||
90 | |||
91 | /** |
||
92 | * Generate a secure random key. |
||
93 | * |
||
94 | * @return string|null |
||
95 | */ |
||
96 | private static function secureRandomKey() |
||
109 | |||
110 | /** |
||
111 | * Get derived key |
||
112 | * http://tools.ietf.org/html/rfc5869. |
||
113 | * |
||
114 | * @param string $ikm Initial Keying Material |
||
115 | * @param string $info What sort of key are we deriving? |
||
116 | * |
||
117 | * @return string |
||
118 | */ |
||
119 | private static function hkdf($ikm, $info = '') |
||
135 | } |
||
136 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: