I was using the mcrypt_get_iv_size function with my website and now it seems that it's deprecated
function Encrypt($word){
$key = '.......';
$iv = mcrypt_create_iv(
mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC),
MCRYPT_DEV_URANDOM
);
$encrypted = base64_encode(
$iv .
mcrypt_encrypt(
MCRYPT_RIJNDAEL_128,
hash('sha256', $key, true),
$word,
MCRYPT_MODE_CBC,
$iv
)
);
return $encrypted;
}
function Decrypt($word){
$key = '.......';
$data = base64_decode($word);
$iv = substr($data, 0, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
$decrypted = rtrim(
mcrypt_decrypt(
MCRYPT_RIJNDAEL_128,
hash('sha256', $key, true),
substr($data, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)),
MCRYPT_MODE_CBC,
$iv
),
"\0"
);
return $decrypted;
}
Now I found a new function from stackoverflow which is this one
function Encrypt($word) {
$key = '.......';
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
$encrypted = openssl_encrypt($word, 'aes-256-cbc', $key, 0, $iv);
return base64_encode($encrypted . '::' . $iv);
}
function Decrypt($word) {
$key = '.......';
list($encrypted_data, $iv) = explode('::', base64_decode($word), 2);
return openssl_decrypt($encrypted_data, 'aes-256-cbc', $key, 0, $iv);
}
My question is: Do I have to use my previously working Decrypt function to get export all my encrypted words from my database and then Encrypt them with the new function and then import/update them into my database? Or is there a way to be able to Decrypt my words from the new function only? Thanks!