4 * Some AES encryption. Works in PHP 4 or 5.
5 * Scrounged on the web, and made to work.
12 function Cipher($textkey) {
13 $this->enc
= MCRYPT_RIJNDAEL_128
;
14 $this->mode
= MCRYPT_MODE_ECB
;
15 $this->securekey
= mhash(MHASH_SHA256
,$textkey);
16 $iv_size = mcrypt_get_iv_size($this->enc
, $this->mode
);
17 $this->iv
= mcrypt_create_iv($iv_size, MCRYPT_DEV_RANDOM
);
20 function encrypt($input) {
21 return mcrypt_encrypt($this->enc
, $this->securekey
, $input, $this->mode
, $this->iv
);
24 function decrypt($input) {
25 return trim(mcrypt_decrypt($this->enc
, $this->securekey
, $input, $this->mode
, $this->iv
));
28 function encrypt2hex($input) {
29 return bin2hex($this->encrypt($input));
32 function decrypthex($input) {
33 return $this->decrypt(pack("H*", $input));
38 $cipher = new Cipher('secret passphrase');
40 $encryptedtext = $cipher->encrypt2hex(pack("H*", "1650f617c024d6441461b2538c6d9540"));
41 echo "->encrypt = $encryptedtext<br />";
43 $decryptedtext = bin2hex($cipher->decrypthex($encryptedtext));
44 echo "->decrypt = $decryptedtext<br />";