Created
November 23, 2015 17:56
-
-
Save v1shwa/4472c4adaa36ee807e96 to your computer and use it in GitHub Desktop.
AES256 CBC Encryption with PKCS7 Padding in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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