From a8c7186b839f85cda0f1abbbae82b0e34a6a65d4 Mon Sep 17 00:00:00 2001 From: Velz2020 Date: Fri, 16 Oct 2020 00:12:36 +0530 Subject: [PATCH] CUSTOME ENCRYPT ADDED --- .../helpers/custom_encryption_helper.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 api/application/helpers/custom_encryption_helper.php diff --git a/api/application/helpers/custom_encryption_helper.php b/api/application/helpers/custom_encryption_helper.php new file mode 100644 index 00000000..b1134d6a --- /dev/null +++ b/api/application/helpers/custom_encryption_helper.php @@ -0,0 +1,83 @@ + + * @author Anant Narayanan + * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD + * @link https://github.com/firebase/php-jwt + */ +class custom_encryption +{ + + + // Store cipher method + static private $ciphering = "BF-CBC"; + public static function encode($str) + { + $string_to_encrypt = $str; + // $string_to_encrypt = 'CJf1ac5a9c47284292d42eadc8f30b75df/20201015'; + // echo "Original String: " . $string_to_encrypt . "\n"; + // Use OpenSSl encryption method + $iv_length = openssl_cipher_iv_length(SELF::$ciphering); + $options = 0; + // echo '$iv_length-'.$iv_length; + // Use random_bytes() function which gives + // randomly 16 digit values + $encryption_iv = random_bytes($iv_length); + // echo '$encryption_iv-'.$encryption_iv; + + // Alternatively, we can use any 16 digit + // characters or numeric for iv + $encryption_key = openssl_digest(php_uname(), 'MD5', TRUE); + // echo '$encryption_key='.$encryption_key; + + // Encryption of string process starts + $encryption = openssl_encrypt($string_to_encrypt, SELF::$ciphering, + $encryption_key, $options, $encryption_iv); + + // Display the encrypted string + // echo "Encrypted String: " . $encryption . "\n"; + return base64_encode($encryption.'.'.$encryption_iv); + } + + + + public static function decode($str) + { + + //echo 'Received-'.base64_decode($str); + $received_data = explode('.',base64_decode($str)); + + $str = $received_data[0]; + // Use OpenSSl encryption method + $iv_length = openssl_cipher_iv_length(SELF::$ciphering); + $options = 0; + // echo '$iv_length-'.$iv_length; + // Decryption of string process starts + // Used random_bytes() which gives randomly + // 16 digit values + // $decryption_iv = random_bytes($iv_length); + $decryption_iv = $received_data[1]; + // echo '$decryption_iv-'.$decryption_iv; + + // Store the decryption key + $decryption_key = openssl_digest(php_uname(), 'MD5', TRUE); + // echo '$encryption_key='.$decryption_key; + + // Descrypt the string + $decryption = openssl_decrypt ($str, SELF::$ciphering, + $decryption_key, $options, $decryption_iv); + + // Display the decrypted string + // echo "Decrypted String: " . $decryption; + return $decryption; + } + +}