From: William Desportes <williamdes@wdes.fr>
Date: Sat, 18 Mar 2023 16:50:06 +0100
Subject: Fix openssl 3 PHP 8 cipher method

Origin: upstream
Forwarded: https://github.com/leenooks/phpLDAPadmin/pull/176/commits/661cab652b279680c07e81b4b71d1955ee2818ab
Forwarded: https://github.com/leenooks/phpLDAPadmin/commit/ef8d0ce94cbb5f17f5a0b25b9bc571e8eb8c5419
---
 lib/functions.php | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/functions.php b/lib/functions.php
index c8e509c..eb5b5dd 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -792,9 +792,9 @@ function blowfish_encrypt($data,$secret=null) {
 	if (! trim($secret))
 		return $data;
 
-	if (! empty($data) && function_exists('openssl_encrypt') && in_array('bf-ecb', openssl_get_cipher_methods())) {
-		$keylen = openssl_cipher_iv_length('bf-ecb') * 2;
-		return openssl_encrypt($data, 'bf-ecb', substr($secret,0,$keylen));
+	if (! empty($data) && function_exists('openssl_encrypt') && in_array('aes-256-gcm', openssl_get_cipher_methods())) {
+		$keylen = openssl_cipher_iv_length('aes-256-gcm') * 2;
+		return openssl_encrypt($data, 'aes-256-gcm', substr($secret,0,$keylen));
 	}
 
 	if (function_exists('mcrypt_module_open') && ! empty($data)) {
@@ -853,9 +853,9 @@ function blowfish_decrypt($encdata,$secret=null) {
 	if (! trim($secret))
 		return $encdata;
 
-	if (! empty($encdata) && function_exists('openssl_encrypt') && in_array('bf-ecb', openssl_get_cipher_methods())) {
-		$keylen = openssl_cipher_iv_length('bf-ecb') * 2;
-		return trim(openssl_decrypt($encdata, 'bf-ecb', substr($secret,0,$keylen)));
+	if (! empty($encdata) && function_exists('openssl_encrypt') && in_array('aes-256-gcm', openssl_get_cipher_methods())) {
+		$keylen = openssl_cipher_iv_length('aes-256-gcm') * 2;
+		return trim(openssl_decrypt($encdata, 'aes-256-gcm', substr($secret,0,$keylen)));
 	}
 
 	if (function_exists('mcrypt_module_open') && ! empty($encdata)) {
