Use a Cryptography Class
(Appendix C, Cryptography - Pg 100)
< Back to Code Repository
<?php
$crypt = new crypt();
$crypt->cleartext = 'This is a string';
$crypt->generate_iv();
$crypt->encrypt();
$ciphertext = base64_encode($crypt->ciphertext);
$iv = base64_encode($crypt->iv);
unset($crypt);
/* Store $ciphertext and $iv (initialization vector). */
$ciphertext = base64_decode($ciphertext);
$iv = base64_decode($iv);
$crypt = new crypt();
$crypt->iv = $iv;
$crypt->ciphertext = $ciphertext;
$crypt->decrypt();
$cleartext = $crypt->cleartext;
?>