Merge branch 'master' of bitbucket.org:venbaittech/sparqapi

This commit is contained in:
VE10-Sanjeev 2022-11-01 14:07:12 +05:30
commit 12867c2dd4
2 changed files with 17 additions and 10 deletions

View File

@ -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];

View File

@ -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;