Archived Forum Post

Index of archived forum posts


How, php crypt to Chilkat Crypt c++?

Nov 21 '12 at 12:31

Ex) PHP Code

//common key
$key = "EncKeyEncKeyEncKey";
$text = "idididididid,passwordpassword";

echo 'plain='.$text.;

list($encrypt, $ivhex) = aesencrypt($text, $key);
echo 'enc='.$encrypt.; echo 'iv='.$ivhex.;

$decrypt = aesdecrypt($encrypt, $key, $ivhex);
echo 'decript='.$decrypt.;

$pos = strpos($decrypt, ','););
$id = substr($decrypt, 0, $pos););
echo 'id='.$id.;
$pass = substr($decrypt, $pos+1);
echo 'pass='.$pass.;

function aesencrypt($text, $key)
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, $iv);

return array(bin2hex($crypttext), bin2hex($iv));


function aesdecrypt($text, $key, $ivhex)
$crypttext = pack('H', $text); $iv = pack('H', $ivhex);

$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);  
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_CBC, $iv);

return $decrypttext;



See this example: