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( |
|
86 | |||
87 | /** |
||
88 | * Generate the authentication key. |
||
89 | * |
||
90 | * @param string $info The extra info parameter for hash_hkdf |
||
91 | * |
||
92 | * @return string |
||
93 | */ |
||
94 | 37 | public function authenticationKey(string $info): string |
|
98 | |||
99 | /** |
||
100 | * Generate the encryption key. |
||
101 | * |
||
102 | * @param string $info The extra info parameter for hash_hkdf |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | 38 | public function encryptionKey(string $info): string |
|
110 | |||
111 | /** |
||
112 | * Derive a key with differing info string parameters. |
||
113 | * |
||
114 | * @param string $info Info parameter to provide to hash_hkdf |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 40 | public function deriveKey(string $info): string |
|
122 | |||
123 | /** |
||
124 | * Generate a new key that meets requirements for dcrypt. |
||
125 | * |
||
126 | * @param int $bytes Size of key in bytes |
||
127 | * |
||
128 | * @throws InvalidKeyException |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | 31 | public static function create(int $bytes = 32): string |
|
140 | } |
||
141 |