]> git.nbdom.net Git - nb.git/commitdiff
lib/php/nb.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 17 Jan 2019 01:24:39 +0000 (02:24 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 17 Jan 2019 01:24:39 +0000 (02:24 +0100)
lib/php/nb.php

index 312cd505a678f861b2c59488849baced34c87151..b1903b65ae33769fa7d67da3b1692faba63a3772 100644 (file)
@@ -975,6 +975,17 @@ class NB {
        }
 
        public static function encrypt($key,$value) {
+       /*
+       # NB 17.01.19: TODO 
+// Remove the base64 encoding from our key
+$encryption_key = base64_decode($key);
+// Generate an initialization vector
+$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
+// Encrypt the data using AES 256 encryption in CBC mode using our encryption key and initialization vector.
+$encrypted = openssl_encrypt($value, 'aes-256-cbc', $key, 0, $iv);
+// The $iv is just as important as the key for decrypting, so save it with our encrypted data using a unique separator (::)
+return base64_encode($encrypted . '::' . $iv);
+       */
                static $iv = null;
                if ($iv === null) {
                        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
@@ -984,6 +995,14 @@ class NB {
        }
 
        public static function decrypt($key,$value) {
+       /*
+       # NB 17.01.19: TODO 
+// Remove the base64 encoding from our key
+$encryption_key = base64_decode($key);
+// To decrypt, split the encrypted data from our IV - our unique separator used was "::"
+list($encrypted_data, $iv) = explode('::', base64_decode($data), 2);
+return openssl_decrypt($encrypted_data, 'aes-256-cbc', $encryption_key, 0, $iv);
+       */
                static $iv_size = null;
                if ($iv_size === null) {
                        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);