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 $_ivr; |
||
54 | |||
55 | /** |
||
56 | * OpensslKey constructor. |
||
57 | * |
||
58 | * @param string $algo Algo to use for HKDF |
||
59 | * @param string $key Key to use for encryption |
||
60 | * @param string $ivr Initialization vector |
||
61 | * |
||
62 | * @throws InvalidKeyException |
||
63 | */ |
||
64 | 49 | public function __construct( |
|
89 | |||
90 | /** |
||
91 | * Generate the authentication key. |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | public function authenticationKey(): string |
||
99 | |||
100 | /** |
||
101 | * Generate the encryption key. |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | public function encryptionKey(): string |
||
109 | |||
110 | 38 | /** |
|
111 | * Derive a key with differing info string parameters. |
||
112 | * |
||
113 | * @param string $info Info parameter to provide to hash_hkdf |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | public function deriveKey(string $info): string |
||
121 | |||
122 | 40 | /** |
|
123 | * Calculates a given message HMAC. |
||
124 | * |
||
125 | * @param string $message |
||
126 | * @return string |
||
127 | */ |
||
128 | public function messageChecksum(string $message): string |
||
132 | |||
133 | /** |
||
134 | 31 | * Returns the iv that object was created with. |
|
135 | * |
||
136 | 31 | * @return string |
|
137 | 1 | */ |
|
138 | public function iv(): string |
||
142 | |||
143 | /** |
||
144 | * Returns the cipher algo that object was created with. |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public function algo(): string |
||
152 | |||
153 | /** |
||
154 | * Generate a new key that meets requirements for dcrypt. |
||
155 | * |
||
156 | * @param int $bytes Size of key in bytes |
||
157 | * |
||
158 | * @return string |
||
159 | * @throws InvalidKeyException |
||
160 | */ |
||
161 | public static function create(int $bytes = 32): string |
||
169 | } |
||
170 |