From 85f8c61e80800a79f9a3457b01ad7338602a3fea Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 2 Apr 2023 00:36:15 +1100 Subject: [PATCH] Fix for Setting of IV length for AEAD mode failed - closes #183 --- lib/functions.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index 870f214..ca421de 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -793,8 +793,10 @@ function blowfish_encrypt($data,$secret=null) { return $data; if (! empty($data) && function_exists('openssl_encrypt') && in_array(SESSION_CIPHER, openssl_get_cipher_methods())) { + $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(SESSION_CIPHER)); $keylen = openssl_cipher_iv_length(SESSION_CIPHER) * 2; - return openssl_encrypt($data, SESSION_CIPHER, substr($secret,0,$keylen)); + $encrypted = openssl_encrypt($data, SESSION_CIPHER, substr($secret,0,$keylen), $options=0, $iv, $tag); + return base64_encode($encrypted . '::' . $iv . '::' . $tag); } if (function_exists('mcrypt_module_open') && ! empty($data)) { @@ -855,7 +857,8 @@ function blowfish_decrypt($encdata,$secret=null) { if (! empty($encdata) && function_exists('openssl_encrypt') && in_array(SESSION_CIPHER, openssl_get_cipher_methods())) { $keylen = openssl_cipher_iv_length(SESSION_CIPHER) * 2; - return trim(openssl_decrypt($encdata, SESSION_CIPHER, substr($secret,0,$keylen))); + list($encryptedData, $iv, $tag) = explode('::', base64_decode($encdata), 3); + return trim(openssl_decrypt($encryptedData, SESSION_CIPHER, substr($secret,0,$keylen), $options=0, $iv, $tag)); } if (function_exists('mcrypt_module_open') && ! empty($encdata)) {