1 | <?php |
||
33 | final class OpensslKey |
||
34 | { |
||
35 | /** |
||
36 | * High entropy key. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | private $_key; |
||
41 | |||
42 | /** |
||
43 | * Algo string. |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | private $_algo; |
||
48 | |||
49 | /** |
||
50 | * High entropy salt. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | private $_iv; |
||
55 | |||
56 | /** |
||
57 | * Name of cipher |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | private $_cipher; |
||
62 | |||
63 | /** |
||
64 | 48 | * OpensslKey constructor. |
|
65 | * |
||
66 | * @param string $key Key to use for encryption |
||
67 | * @param string $algo Algo to use for HKDF |
||
68 | * @param string $cipher Name of cipher |
||
69 | * @param string $iv Initialization vector |
||
70 | 48 | * |
|
71 | * @throws InvalidKeyException |
||
72 | */ |
||
73 | 48 | public function __construct( |
|
102 | |||
103 | /** |
||
104 | * Generate the authentication key. |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | 37 | public function authenticationKey(): string |
|
112 | |||
113 | /** |
||
114 | * Generate the encryption key. |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | public function encryptionKey(): string |
||
122 | 39 | ||
123 | /** |
||
124 | * Derive a key with differing info string parameters. |
||
125 | * |
||
126 | * @param string $info Info parameter to provide to hash_hkdf |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | public function deriveKey(string $info): string |
||
134 | 31 | ||
135 | /** |
||
136 | 31 | * Calculates a given message HMAC. |
|
137 | 1 | * |
|
138 | * @param string $message |
||
139 | * @return string |
||
140 | 31 | */ |
|
141 | public function messageChecksum(string $message): string |
||
145 | |||
146 | /** |
||
147 | * Allows secure read only access to private properties |
||
148 | * |
||
149 | * @param string $name |
||
150 | * @return mixed |
||
151 | * @throws Exception |
||
152 | */ |
||
153 | public function __get(string $name) |
||
161 | |||
162 | /** |
||
163 | * Generate a new key. |
||
164 | * |
||
165 | * @param int $bytes Size of key in bytes |
||
166 | * |
||
167 | * @return string |
||
168 | * @throws InvalidKeyException |
||
169 | * @throws Exception |
||
170 | */ |
||
171 | public static function create(int $bytes = 32): string |
||
179 | } |
||
180 |