Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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