1 | <?php |
||
32 | final class OpensslKey |
||
33 | { |
||
34 | /** |
||
35 | * High entropy key. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | private $_key; |
||
40 | |||
41 | /** |
||
42 | * Algo string. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | private $_algo; |
||
47 | |||
48 | /** |
||
49 | * High entropy salt. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $_iv; |
||
54 | |||
55 | /** |
||
56 | * Name of cipher |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | private $_cipher; |
||
61 | |||
62 | /** |
||
63 | * OpensslKey constructor. |
||
64 | * |
||
65 | * @param string $key Key to use for encryption |
||
66 | * @param string $algo Algo to use for HKDF |
||
67 | * @param string $cipher Name of cipher |
||
68 | * @param string $ivr Initialization vector |
||
69 | * |
||
70 | * @throws InvalidKeyException |
||
71 | */ |
||
72 | 48 | public function __construct( |
|
101 | |||
102 | /** |
||
103 | * Generate the authentication key. |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | 36 | public function authenticationKey(): string |
|
111 | |||
112 | /** |
||
113 | * Generate the encryption key. |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 37 | public function encryptionKey(): string |
|
121 | |||
122 | /** |
||
123 | * Derive a key with differing info string parameters. |
||
124 | * |
||
125 | * @param string $info Info parameter to provide to hash_hkdf |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | 39 | public function deriveKey(string $info): string |
|
133 | |||
134 | /** |
||
135 | * Calculates a given message HMAC. |
||
136 | * |
||
137 | * @param string $message |
||
138 | * @return string |
||
139 | */ |
||
140 | 36 | public function messageChecksum(string $message): string |
|
144 | |||
145 | /** |
||
146 | * Returns the iv that object was created with. |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | 37 | public function iv(): string |
|
154 | |||
155 | /** |
||
156 | * Returns the cipher name |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | 36 | public function cipher(): string |
|
164 | |||
165 | /** |
||
166 | * Returns the cipher algo that object was created with. |
||
167 | * |
||
168 | * @return string |
||
169 | */ |
||
170 | public function algo(): string |
||
174 | |||
175 | /** |
||
176 | * Generate a new key that meets requirements for dcrypt. |
||
177 | * |
||
178 | * @param int $bytes Size of key in bytes |
||
179 | * |
||
180 | * @return string |
||
181 | * @throws InvalidKeyException |
||
182 | */ |
||
183 | 31 | public static function create(int $bytes = 32): string |
|
191 | } |
||
192 |