SF Feature #2900545 - blowfish using mcrypt

This commit is contained in:
Dmitry Bakshaev 2011-04-29 13:31:17 +10:00 committed by Deon George
parent e083f5f8b5
commit 775e6f40d4

View File

@ -745,6 +745,16 @@ function blowfish_encrypt($data,$secret=null) {
if (! trim($secret))
return $data;
if (function_exists('mcrypt_module_open')) {
$td = mcrypt_module_open(MCRYPT_BLOWFISH,'',MCRYPT_MODE_ECB,'');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_DEV_URANDOM);
mcrypt_generic_init($td,substr($secret,0,mcrypt_enc_get_key_size($td)),$iv);
$encrypted_data = base64_encode(mcrypt_generic($td,$data));
mcrypt_generic_deinit($td);
return $encrypted_data;
}
if (file_exists(LIBDIR.'blowfish.php'))
require_once LIBDIR.'blowfish.php';
else
@ -790,6 +800,16 @@ function blowfish_decrypt($encdata,$secret=null) {
if (! trim($secret))
return $encdata;
if (function_exists('mcrypt_module_open')) {
$td = mcrypt_module_open(MCRYPT_BLOWFISH,'',MCRYPT_MODE_ECB,'');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_DEV_URANDOM);
mcrypt_generic_init($td,substr($secret,0,mcrypt_enc_get_key_size($td)),$iv);
$decrypted_data = trim(mdecrypt_generic($td,base64_decode($encdata)));
mcrypt_generic_deinit($td);
return $decrypted_data;
}
if (file_exists(LIBDIR.'blowfish.php'))
require_once LIBDIR.'blowfish.php';
else