From: Nicolas Boisselier Date: Sat, 13 Jul 2019 04:21:19 +0000 (+0100) Subject: /opt/nb/lib/php/nb.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=6d7cad9422aebb1d8d1a14c414b7a13d83ad8743;p=nb.git /opt/nb/lib/php/nb.php --- diff --git a/lib/php/nb.php b/lib/php/nb.php index 791bb0e5..7be76278 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -926,7 +926,30 @@ class NB { return bin2hex(mcrypt_create_iv($length/2, MCRYPT_DEV_URANDOM)); } + private static function _encrypt_decrypt_object($key) { + static $cipher = null; + if ($cipher === null) { + #require_once(NB_ROOT.'/lib/php/phpseclib/Crypt/AES.php'); + #require_once(NB_ROOT.'/lib/php/phpseclib/Crypt/Random.php'); + require_once(NB_ROOT.'/usr/share/php/Crypt/AES.php'); + require_once(NB_ROOT.'/usr/share/php/Crypt/Random.php'); + $cipher = new Crypt_AES(); + } + if (!empty($key)) $cipher->setIV($key); + return $cipher; +# NB 31.01.19 return self::_encrypt_decrypt_object($key)->decrypt($value); + } + + public static function _decrypt($key,$value) { + return self::_encrypt_decrypt_object($key)->decrypt(base64_decode($value)); + } + + public static function _encrypt($key,$value) { + return base64_encode(self::_encrypt_decrypt_object($key)->encrypt($value)); + } + public static function encrypt($key,$value) { + #return self::_encrypt($key,$value); static $iv = null; if ($iv === null) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); @@ -936,6 +959,7 @@ class NB { } public static function decrypt($key,$value) { + #return self::_decrypt($key,$value); static $iv_size = null; if ($iv_size === null) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);