Skip to content

Instantly share code, notes, and snippets.

@shikendon
Created April 7, 2016 04:48
Show Gist options
  • Save shikendon/6bf70d9be35a646270ac4dab2aa60720 to your computer and use it in GitHub Desktop.
Save shikendon/6bf70d9be35a646270ac4dab2aa60720 to your computer and use it in GitHub Desktop.
RIJNDAEL 128 CBC encryption PHP snippet
<?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