Merge pull request #60 from NHellFire/php7.1

Use OpenSSL for blowfish when available (fixes #58)
This commit is contained in:
Deon George 2019-04-18 12:16:08 +10:00 committed by GitHub
commit aa11e318ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -745,6 +745,11 @@ 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 (function_exists('mcrypt_module_open') && ! empty($data)) {
$td = mcrypt_module_open(MCRYPT_BLOWFISH,'',MCRYPT_MODE_ECB,'');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_DEV_URANDOM);
@ -801,6 +806,11 @@ 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 (function_exists('mcrypt_module_open') && ! empty($encdata)) {
$td = mcrypt_module_open(MCRYPT_BLOWFISH,'',MCRYPT_MODE_ECB,'');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_DEV_URANDOM);