Skip to content

Instantly share code, notes, and snippets.

Created May 5, 2011 15:45
Show Gist options
  • Save anonymous/957281 to your computer and use it in GitHub Desktop.
Save anonymous/957281 to your computer and use it in GitHub Desktop.
AES256/ECB/PKCS7Padding Encrypt/Decrypt in PHP
function aes256EcbPkcs7PaddingEncrypt($key, $data) {
$padding = 16 - (strlen($data) % 16);
$data .= str_repeat(chr($padding), $padding);
return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, hash('SHA256', $key, true), $data, MCRYPT_MODE_ECB);
}
function aes256EcbPkcs7PaddingDecrypt($key, $data) {
$data = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, hash('SHA256', $key, true), $data, MCRYPT_MODE_ECB);
$padding = ord($data[strlen($data) - 1]);
return substr($data, 0, -$padding);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment