From 56b69fc30314e835a97c55ac879d7b0f144ca934 Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Sun, 7 Feb 2021 17:58:42 +0100 Subject: [PATCH] base64_encode() encrypted binary data --- Classes/Common/Helper.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Classes/Common/Helper.php b/Classes/Common/Helper.php index 176721ef..e6265ca1 100644 --- a/Classes/Common/Helper.php +++ b/Classes/Common/Helper.php @@ -185,11 +185,12 @@ class Helper return false; } // Split initialisation vector and encrypted data. - $iv = substr($encrypted, 0, openssl_cipher_iv_length(self::$cipherAlgorithm)); - $data = substr($encrypted, openssl_cipher_iv_length(self::$cipherAlgorithm)); + $binary = base64_decode($encrypted); + $iv = substr($binary, 0, openssl_cipher_iv_length(self::$cipherAlgorithm)); + $data = substr($binary, openssl_cipher_iv_length(self::$cipherAlgorithm)); $key = openssl_digest($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], self::$hashAlgorithm, true); // Decrypt data. - $decrypted = openssl_decrypt($data, self::$cipherAlgorithm, $key, 0, $iv); + $decrypted = openssl_decrypt($data, self::$cipherAlgorithm, $key, OPENSSL_RAW_DATA, $iv); return $decrypted; } @@ -282,10 +283,10 @@ class Helper $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(self::$cipherAlgorithm)); $key = openssl_digest($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], self::$hashAlgorithm, true); // Encrypt data. - $encrypted = openssl_encrypt($string, self::$cipherAlgorithm, $key, 0, $iv); + $encrypted = openssl_encrypt($string, self::$cipherAlgorithm, $key, OPENSSL_RAW_DATA, $iv); // Merge initialisation vector and encrypted data. if ($encrypted !== false) { - $encrypted = $iv . $encrypted; + $encrypted = base64_encode($iv . $encrypted); } return $encrypted; }