From dd0c5a20dbc3d7435554a10471a0fc1d15faa364 Mon Sep 17 00:00:00 2001 From: Velz2020 Date: Mon, 31 Oct 2022 22:46:00 +0530 Subject: [PATCH] ENCRYPT CHANGED --- api/application/controllers/Welcome.php | 9 ++++++--- .../helpers/custom_encryption_helper.php | 18 +++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/api/application/controllers/Welcome.php b/api/application/controllers/Welcome.php index 3e57a0eb..7350e4fb 100644 --- a/api/application/controllers/Welcome.php +++ b/api/application/controllers/Welcome.php @@ -49,10 +49,13 @@ class Welcome extends CI_Controller { $data = $this->input->get('dat'); if($data) { - - // $uri = custom_encryption::encode($data);die(); + // $data = 'vdo/20221031/1010/random'; + // $uri = custom_encryption::encode($data); + $uri = custom_encryption::decode($data); - // echo $uri; + // echo $uri; + // die(); + $uri = explode('/',$uri); // print_r($uri);die(); $pd_id = $uri[2]; diff --git a/api/application/helpers/custom_encryption_helper.php b/api/application/helpers/custom_encryption_helper.php index b1134d6a..b1a9324c 100644 --- a/api/application/helpers/custom_encryption_helper.php +++ b/api/application/helpers/custom_encryption_helper.php @@ -18,7 +18,8 @@ class custom_encryption // Store cipher method - static private $ciphering = "BF-CBC"; + static private $ciphering = "AES-256-CBC"; + static private $key = "Awuc64pVpcB9xf"; public static function encode($str) { $string_to_encrypt = $str; @@ -30,12 +31,13 @@ class custom_encryption // echo '$iv_length-'.$iv_length; // Use random_bytes() function which gives // randomly 16 digit values - $encryption_iv = random_bytes($iv_length); + // $encryption_iv = random_bytes($iv_length); + $encryption_iv = openssl_random_pseudo_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); + $encryption_key = openssl_digest(SELF::$key, 'MD5', TRUE); // echo '$encryption_key='.$encryption_key; // Encryption of string process starts @@ -44,7 +46,9 @@ class custom_encryption // Display the encrypted string // echo "Encrypted String: " . $encryption . "\n"; - return base64_encode($encryption.'.'.$encryption_iv); + return base64_encode($encryption.'.'.base64_encode($encryption_iv)); + + // return base64_encode(openssl_encrypt($data, $this->method, $this->key, 0, $iv) . $this->separator . base64_encode($iv)); } @@ -64,16 +68,16 @@ class custom_encryption // Used random_bytes() which gives randomly // 16 digit values // $decryption_iv = random_bytes($iv_length); - $decryption_iv = $received_data[1]; + $decryption_iv = base64_decode($received_data[1]); // echo '$decryption_iv-'.$decryption_iv; // Store the decryption key - $decryption_key = openssl_digest(php_uname(), 'MD5', TRUE); + $decryption_key = openssl_digest(SELF::$key, 'MD5', TRUE); // echo '$encryption_key='.$decryption_key; // Descrypt the string $decryption = openssl_decrypt ($str, SELF::$ciphering, - $decryption_key, $options, $decryption_iv); + $decryption_key, $options, ($decryption_iv)); // Display the decrypted string // echo "Decrypted String: " . $decryption;