Question:
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.;
exit;
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;
}