@@ -160,7 +160,7 @@ |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | - * Decrypts the given data. |
|
163 | + * Decrypts the given data. |
|
164 | 164 | * |
165 | 165 | * @param string $data Data to decrypt. |
166 | 166 | * @return string decrypted data |
@@ -48,22 +48,22 @@ discard block |
||
48 | 48 | */ |
49 | 49 | |
50 | 50 | private $_supportedCiphers = [ |
51 | - 'aes-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
52 | - 'aes-128-gcm' => [ 'tag' => true, 'key' => 16 ], |
|
53 | - 'aes-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
54 | - 'aes-192-gcm' => [ 'tag' => true, 'key' => 24 ], |
|
55 | - 'aes-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
56 | - 'aes-256-gcm' => [ 'tag' => true, 'key' => 32 ], |
|
57 | - 'chacha20' => [ 'tag' => false, 'key' => 32 ], |
|
58 | - 'camellia-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
59 | - 'camellia-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
60 | - 'camellia-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
61 | - 'aria-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
62 | - 'aria-128-gcm' => [ 'tag' => true, 'key' => 16 ], |
|
63 | - 'aria-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
64 | - 'aria-192-gcm' => [ 'tag' => true, 'key' => 24 ], |
|
65 | - 'aria-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
66 | - 'aria-256-gcm' => [ 'tag' => true, 'key' => 32 ], |
|
51 | + 'aes-128-cbc' => ['tag' => false, 'key' => 16], |
|
52 | + 'aes-128-gcm' => ['tag' => true, 'key' => 16], |
|
53 | + 'aes-192-cbc' => ['tag' => false, 'key' => 24], |
|
54 | + 'aes-192-gcm' => ['tag' => true, 'key' => 24], |
|
55 | + 'aes-256-cbc' => ['tag' => false, 'key' => 32], |
|
56 | + 'aes-256-gcm' => ['tag' => true, 'key' => 32], |
|
57 | + 'chacha20' => ['tag' => false, 'key' => 32], |
|
58 | + 'camellia-128-cbc' => ['tag' => false, 'key' => 16], |
|
59 | + 'camellia-192-cbc' => ['tag' => false, 'key' => 24], |
|
60 | + 'camellia-256-cbc' => ['tag' => false, 'key' => 32], |
|
61 | + 'aria-128-cbc' => ['tag' => false, 'key' => 16], |
|
62 | + 'aria-128-gcm' => ['tag' => true, 'key' => 16], |
|
63 | + 'aria-192-cbc' => ['tag' => false, 'key' => 24], |
|
64 | + 'aria-192-gcm' => ['tag' => true, 'key' => 24], |
|
65 | + 'aria-256-cbc' => ['tag' => false, 'key' => 32], |
|
66 | + 'aria-256-gcm' => ['tag' => true, 'key' => 32], |
|
67 | 67 | ]; |
68 | 68 | |
69 | 69 | /** |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | // A longer key is not a problem, but could indicate a configuration error |
137 | 137 | $key_length = $this->_supportedCiphers[$this->_cipher]['key']; |
138 | 138 | if (strlen($key) != $key_length) { |
139 | - throw new RuntimeException("Invalid length of key with key_id '{$this->_key_id}' used with cipher '{$this->_cipher}', expected {$key_length} bytes, got " . strlen($key) . " bytes"); |
|
139 | + throw new RuntimeException("Invalid length of key with key_id '{$this->_key_id}' used with cipher '{$this->_cipher}', expected {$key_length} bytes, got ".strlen($key)." bytes"); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // openssl_encrypt returns the ciphertext as a base64 encoded string, so we don't need to encode it again |
143 | 143 | // The tag is returned as a binary string, but only if the cipher requires a tag |
144 | - $tag=''; |
|
144 | + $tag = ''; |
|
145 | 145 | if ($this->_supportedCiphers[$this->_cipher]['tag']) { |
146 | 146 | $encrypted = openssl_encrypt($data, $this->_cipher, $key, 0, $iv, $tag, '', 16); |
147 | 147 | } else { |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $tag = $this->_supportedCiphers[$this->_cipher]['tag'] ? $tag : ''; |
154 | 154 | // Return the encoded ciphertext, including the IV, tag and cipher |
155 | 155 | // <cipher>:<key_id>:iv<>:<tag>:<ciphertext> |
156 | - $encoded = $this->_cipher . ":" . $this->_key_id . ":" . base64_encode($iv) . ":" . base64_encode($tag) . ":" . $encrypted; |
|
156 | + $encoded = $this->_cipher.":".$this->_key_id.":".base64_encode($iv).":".base64_encode($tag).":".$encrypted; |
|
157 | 157 | |
158 | 158 | return $encoded; |
159 | 159 | } |
@@ -192,19 +192,19 @@ discard block |
||
192 | 192 | } |
193 | 193 | |
194 | 194 | // IV |
195 | - $iv = base64_decode($split_data[2],true); |
|
195 | + $iv = base64_decode($split_data[2], true); |
|
196 | 196 | if ($iv === false) { |
197 | 197 | throw new RuntimeException("Error decoding IV"); |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Tag |
201 | - $tag = base64_decode($split_data[3],true); |
|
201 | + $tag = base64_decode($split_data[3], true); |
|
202 | 202 | if ($tag === false) { |
203 | 203 | throw new RuntimeException("Error decoding tag"); |
204 | 204 | } |
205 | 205 | $ciphertext = $split_data[4]; |
206 | 206 | |
207 | - $plaintext=openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag); |
|
207 | + $plaintext = openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag); |
|
208 | 208 | if ($plaintext === false) { |
209 | 209 | throw new RuntimeException("Error decrypting data"); |
210 | 210 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
60 | - * Decrypts the given data. |
|
60 | + * Decrypts the given data. |
|
61 | 61 | * |
62 | 62 | * @param String $data Data to decrypt. |
63 | 63 | * |