2010년 3월 10일 수요일
[쿠키 암호화] Function #1 (MD5 + Base64)
[code php]function encrypt_md5_base64($plain_text, $password="password", $iv_len = 16)
{
$plain_text .= "\x13";
$n = strlen($plain_text);
if ($n % 16) $plain_text .= str_repeat("\0", 16 - ($n % 16));
$i = 0;
while ($iv_len-- >0)
{
$enc_text .= chr(mt_rand() & 0xff);
}
$iv = substr($password ^ $enc_text, 0, 512);
while($i <$n)
{
$block = substr($plain_text, $i, 16) ^ pack('H*', md5($iv));
$enc_text .= $block;
$iv = substr($block . $iv, 0, 512) ^ $password;
$i += 16;
}
return base64_encode($enc_text);
}
function decrypt_md5_base64($enc_text, $password="password", $iv_len = 16)
{
$enc_text = base64_decode($enc_text);
$n = strlen($enc_text);
$i = $iv_len;
$plain_text = '';
$iv = substr($password ^ substr($enc_text, 0, $iv_len), 0, 512);
while($i <$n)
{
$block = substr($enc_text, $i, 16);
$plain_text .= $block ^ pack('H*', md5($iv));
$iv = substr($block . $iv, 0, 512) ^ $password;
$i += 16;
}
return preg_replace('/\x13\x00*$/', '', $plain_text);
}
/******************************************/
$name = '홍길동';
$enc_name = encrypt_md5_base64($name);
$dec_name = decrypt_md5_base64($enc_name);
echo "name = {$name}\n\n";
echo "encode_name = {$enc_name}\n\n";
echo "decode_name = {$dec_name}\n\n";[/code]
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기