]> git.nbdom.net Git - nb.git/commitdiff
/opt/nb/lib/php/nb.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 13 Jul 2019 04:21:19 +0000 (05:21 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 13 Jul 2019 04:21:19 +0000 (05:21 +0100)
lib/php/nb.php

index 791bb0e5655a9ec78e571e54d1e88698cf9ac56f..7be76278d54fddd6d2e335c9a14cb76d5ccfac9a 100644 (file)
@@ -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);