Skip to content

Instantly share code, notes, and snippets.

@jeffreyroberts
Last active December 31, 2015 10:39
Show Gist options
  • Save jeffreyroberts/7974872 to your computer and use it in GitHub Desktop.
Save jeffreyroberts/7974872 to your computer and use it in GitHub Desktop.
aes encrypt and decrypt
<?php
function aes_decrypt($code, $key, $iv) {
$mode = MCRYPT_MODE_CBC;
$enc = MCRYPT_RIJNDAEL_128;
return mcrypt_decrypt($enc, $key, $code, $mode, $iv);
}
function aes_encrypt($code, $key, $iv) {
$mode = MCRYPT_MODE_CBC;
$enc = MCRYPT_RIJNDAEL_128;
return mcrypt_encrypt($enc, $key, $code, $mode, $iv);
}
$encryptable = 'asdfasdfasdf';
$iv = "000000000000000" . dechex(1);
$key = '238EF4477A3ADD32385C584EED6A4B8B';
$encrypted = aes_encrypt($encryptable, $key, $iv);
//PROVA DELLE FUNZIONI
$test2 = aes_decrypt($encrypted, $key, $iv);
echo $test2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment