I'm trying to do an ecrypt decrypt on php. An old function written by a colleague for the encryption and decryption using MCRYPT RINJDAEL-128-CBC is as follows. Encrypt
$key = pack('H*', $salt);
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_MODE_CBC, $iv);
return base64_encode($iv . $ciphertext);
}
Decrypt
$key = pack('H*', $salt);
$ciphertext_dec = base64_decode($encodedText);
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv_dec = substr($ciphertext_dec, 0, $iv_size);
$ciphertext_dec = substr($ciphertext_dec, $iv_size);
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec);
}```
Due to php deprecating Mcrypt and only uses Openssl, how would I write a function that can do exactly the same?