Created
April 7, 2016 04:48
-
-
Save shikendon/6bf70d9be35a646270ac4dab2aa60720 to your computer and use it in GitHub Desktop.
RIJNDAEL 128 CBC encryption PHP snippet
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 addpadding($string, $blocksize = 32) { | |
$len = strlen($string); | |
$pad = $blocksize - ($len % $blocksize); | |
$string .= str_repeat(chr($pad), $pad); | |
return $string; | |
} | |
$key = '12345678901234567890123456789012'; | |
$post_data_str = 'abcdefghijklmnop'; | |
$iv = '1234567890123456'; | |
$encrypted = bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, addpadding($post_data_str), MCRYPT_MODE_CBC, $iv)); | |
echo $encrypted; // b91d3ece42c203729b38ae004e96efb9b64c41eeb074cad7ebafa3973181d233 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment