Skip to content

Instantly share code, notes, and snippets.

@v1shwa
Created November 23, 2015 17:56
Show Gist options
  • Save v1shwa/4472c4adaa36ee807e96 to your computer and use it in GitHub Desktop.
Save v1shwa/4472c4adaa36ee807e96 to your computer and use it in GitHub Desktop.
AES256 CBC Encryption with PKCS7 Padding in PHP
<?php
function aes256_cbc($data, $key, $iv)
{
// padding
$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,'cbc');
$len = strlen($data);
$pad = $blocksize - ($len % $blocksize);
$data .= str_repeat(chr($pad), $pad);
// encrypting & encoding
return base64_encode( mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv) ) ;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment