日期:2014-05-17 浏览次数:20666 次
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
header("Content-Type:text/html; charset=utf-8");
$str="床前明月光,疑是地上霜"; //被加密的内容
$key="key:111"; //密匙
$cipher=MCRYPT_DES; //加密算法类型
$mode=MCRYPT_MODE_ECB; //加密算法模式
$iv=mcrypt_create_iv(mcrypt_get_iv_size($cipher, $mode),MCRYPT_RAND); //初始化向量
echo "加密前".$str."<br>";
//加密
$str_encrypt=mcrypt_encrypt($cipher,$key,$str,$mode,$iv);
echo "加密后".$str_encrypt."<br>";
//还原
$str_decrypt=mcrypt_encrypt($cipher,$key,$str_encrypt,$mode,$iv);
echo "还原".$str_decrypt."<br>";
?>