Skip to content

Instantly share code, notes, and snippets.

View RiANOl's full-sized avatar

Rianol Jou RiANOl

View GitHub Profile
@RiANOl
RiANOl / gist:1077723
Last active April 4, 2024 08:34 — forked from anonymous/gist:957281
AES128 / AES256 CBC with PKCS7Padding in PHP
<?
function aes128_cbc_encrypt($key, $data, $iv) {
if(16 !== strlen($key)) $key = hash('MD5', $key, true);
if(16 !== strlen($iv)) $iv = hash('MD5', $iv, true);
$padding = 16 - (strlen($data) % 16);
$data .= str_repeat(chr($padding), $padding);
return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv);
}