From: Nicolas Boisselier Date: Sat, 13 Jul 2019 04:58:05 +0000 (+0100) Subject: /opt/nb/lib/php/nb.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=fa5d27d0885b9dcbcf03c45a57050fa92c56c685;p=nb.git /opt/nb/lib/php/nb.php --- diff --git a/lib/php/nb.php b/lib/php/nb.php index 7be76278..d7a456bf 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -926,30 +926,8 @@ 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); + return self::_encrypt($key,$value); static $iv = null; if ($iv === null) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); @@ -959,7 +937,7 @@ class NB { } public static function decrypt($key,$value) { - #return self::_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); @@ -968,6 +946,26 @@ class NB { return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, substr($value, $iv_size), MCRYPT_MODE_CBC, substr($value, 0, $iv_size))); } + private static function _encrypt_decrypt_object($key) { + static $cipher = null; + if ($cipher === null) { + require_once '/usr/share/php/phpseclib.autoloader.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) { + debug($key); + 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 is_vm() { return file_exists('/proc/cpuinfo') && preg_match('/^flags.* hypervisor/m',file_get_contents('/proc/cpuinfo')); }