From 775e6f40d438832a813e33adf4c6afd80cf90430 Mon Sep 17 00:00:00 2001 From: Dmitry Bakshaev Date: Fri, 29 Apr 2011 13:31:17 +1000 Subject: [PATCH] SF Feature #2900545 - blowfish using mcrypt --- lib/functions.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/functions.php b/lib/functions.php index 87d0bf6..381a434 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -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