Skip to content

Commit

Permalink
Merge pull request #3 from NHellFire/php7.1
Browse files Browse the repository at this point in the history
Use OpenSSL for blowfish when available (fixes #58)
  • Loading branch information
lifehome committed Mar 14, 2018
2 parents b148845 + 53e005c commit d7eff5a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,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);
Expand Down Expand Up @@ -803,6 +808,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);
Expand Down

0 comments on commit d7eff5a

Please sign in to comment.