@@ -20,21 +20,21 @@ discard block |
||
| 20 | 20 | $data = json_encode($data); // TODO throw exception if false |
| 21 | 21 | |
| 22 | 22 | $ivLen = openssl_cipher_iv_length($cipherMethod); |
| 23 | - if($ivLen === false) { |
|
| 23 | + if ($ivLen === false) { |
|
| 24 | 24 | throw new SymmetricEncryptionException( |
| 25 | 25 | 'openssl_cipher_iv_length() returned false', |
| 26 | 26 | SymmetricEncryptionException::OPENSSL_ERROR |
| 27 | 27 | ); |
| 28 | 28 | } |
| 29 | 29 | $iv = openssl_random_pseudo_bytes($ivLen); |
| 30 | - if(!$iv) { |
|
| 30 | + if (!$iv) { |
|
| 31 | 31 | throw new SymmetricEncryptionException( |
| 32 | 32 | 'openssl_random_pseudo_bytes() returned false', |
| 33 | 33 | SymmetricEncryptionException::OPENSSL_ERROR |
| 34 | 34 | ); |
| 35 | 35 | } |
| 36 | 36 | $cipherText = openssl_encrypt($data, $cipherMethod, $secretKey, OPENSSL_RAW_DATA, $iv); |
| 37 | - if($cipherText === false) { |
|
| 37 | + if ($cipherText === false) { |
|
| 38 | 38 | throw new SymmetricEncryptionException( |
| 39 | 39 | 'openssl_encrypt() returned false', |
| 40 | 40 | SymmetricEncryptionException::OPENSSL_ERROR |
@@ -58,19 +58,19 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | $c = base64_decode($encryptedData); |
| 60 | 60 | $ivLen = openssl_cipher_iv_length($cipherMethod); |
| 61 | - if($ivLen === false) { |
|
| 61 | + if ($ivLen === false) { |
|
| 62 | 62 | throw new SymmetricEncryptionException( |
| 63 | 63 | 'openssl_cipher_iv_length() returned false', |
| 64 | 64 | SymmetricEncryptionException::OPENSSL_ERROR |
| 65 | 65 | ); |
| 66 | 66 | } |
| 67 | 67 | $iv = substr($c, 0, $ivLen); |
| 68 | - $hmac = substr($c, $ivLen, $sha2len=32); |
|
| 68 | + $hmac = substr($c, $ivLen, $sha2len = 32); |
|
| 69 | 69 | $cipherText = substr($c, $ivLen+$sha2len); |
| 70 | 70 | |
| 71 | 71 | $data = openssl_decrypt($cipherText, $cipherMethod, $secretKey, OPENSSL_RAW_DATA, $iv); |
| 72 | 72 | |
| 73 | - if($data === false) { |
|
| 73 | + if ($data === false) { |
|
| 74 | 74 | throw new SymmetricEncryptionException( |
| 75 | 75 | 'incorrect secret key', |
| 76 | 76 | SymmetricEncryptionException::CANNOT_DECRYPT |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public static function checkCipherMethodAvailable(string $cipherMethod): void |
| 95 | 95 | { |
| 96 | - if(!in_array($cipherMethod, static::getCipherMethodList(), true)) { |
|
| 96 | + if (!in_array($cipherMethod, static::getCipherMethodList(), true)) { |
|
| 97 | 97 | throw new SymmetricEncryptionException( |
| 98 | 98 | "unknown cipher method '{$cipherMethod}'", |
| 99 | 99 | SymmetricEncryptionException::UNKNOWN_METHOD |