How do I setup my IV in codeigniter 3 encryption library?
I have encryption code below which was running smoothly in Codeigniter 2 with PHP 5.6,
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));
}
When I upgraded to CI 3 with PHP 7.1 mcrypt was deprecated already. So, I wanted to recreate the function in CI 3 using encryption library, but I cannot get the correct encrypted strings.
$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));