login about faq

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;

}

asked Nov 18 '12 at 22:00

berserk77's gravatar image

berserk77
1112

edited Nov 18 '12 at 22:08


link

answered Nov 21 '12 at 12:31

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×65
×35
×4

Asked: Nov 18 '12 at 22:00

Seen: 1,764 times

Last updated: Nov 21 '12 at 12:31

powered by OSQA