Welcome Guest, Not a member yet? Register   Sign In
Cannot get the right encryption MYCRYPT
#1

Using the old encrypt function that I wrote in CI2 with PHP 5.6


I get the result like this 

tgpzkS8fLTcuYW1XQtYoVQ%3D%3D  (Correct)


Code:
$amount = 1100;

[size=small][font=Monaco, Consolas, Courier, monospace]$json = array([/font][/size]
[size=small][font=Monaco, Consolas, Courier, monospace]'Amount' => $amount[/font][/size]
);

$data = json_encode($json);

function encrypt($data, $secret) 

  //Generate a key from a hash 
    $key = md5(utf8_encode($secret), true); 
    $data2 = utf8_encode($data); 
    $iv = utf8_encode("jvz8bUAx"); 
    
    //Take first 8 bytes of $key and append them to the end of $key. 
    $key .= substr($key, 0, 8); 
   
    //Pad for PKCS7 
    $blockSize = mcrypt_get_block_size('tripledes', 'cbc'); 
 
    //Encrypt data 
    $encData = mcrypt_encrypt('tripledes', $key, $data2, MCRYPT_MODE_CBC, $iv); 
      
    return urlencode(base64_encode($encData)); 


After I upgraded my project to CI 3 with PHP 7.1

The result I get now is. N4iCloGQTBn%2Fp5sUAK7OwFR3QBY57fsr  (Wrong)


Code:
$this->load->library('encryption');

$key = md5(utf8_encode($secret), true); 
$key .= substr($key, 0, 8); 
$iv = utf8_encode("jvz8bUAx"); 

$amount = 1100;

$json = array(
'Amount' => $amount
);

$data = json_encode($json);

$params = array(
        'driver' => 'mcrypt',
                'cipher' => 'tripledes',
                'mode' => 'cbc',
                'key' => $key,
                'hmac' => false
        );

$ciphertext = $this->encryption->encrypt($data, $params);
$ciphertext = urlencode(base64_encode($ciphertext));

return $ciphertext;

Can you help me how can I return same result just like above in my current tasks?
Also, how do I set up my IV value? 


Thanks,
Reply




Theme © iAndrew 2016 - Forum software by © MyBB