我也不知道是什么问题啦~~烦四了~~(关于Mcrypt)
hodat 2003-08-21 10:59:05 我的代码:
-----------------------------
<?
$EnCoder_Key="WelCome 2 The 9 Station !@#$%";
$EnCoder_type=MCRYPT_RIJNDAEL_128; //加密类型
$string[]="我爱逆水行舟大声疾呼";
$string[]="认证介绍 精选Dump 精选文章";
$string[]="网站加速 PHP 缓冲的免费实现方法";
$string[]="用PHP写的SMTP类,支持附件(多个),";
$string[]="在编辑器中带颜色,如果您还没有";
for($i=0;$i<count($string);$i++){
$tt[]=Do_Crypt($string[$i]);
}
echo "<pre>";
print_r($tt);
echo "</pre>";
for($k=0;$k<count($tt);$k++){
$kk[]=Do_Uncrypt($tt[$k]);
}
echo "<pre>";
print_r($kk);
echo "</pre>";
function Do_Crypt($s){
global $EnCoder_Key,$EnCoder_type;
$iv = mcrypt_create_iv(mcrypt_get_iv_size($EnCoder_type,MCRYPT_MODE_ECB), MCRYPT_RAND);
$encrypted_stringa = mcrypt_encrypt( $EnCoder_type, $EnCoder_Key, trim($s), MCRYPT_MODE_CBC, $iv);
$encrypted_string = bin2hex($encrypted_stringa);
return $encrypted_string;
}
function Do_Uncrypt($s){
global $EnCoder_Key,$EnCoder_type;
$saa=trim($s);
unset($string_en);
$string_en=hex2bin($saa);
$iv = mcrypt_create_iv(mcrypt_get_iv_size($EnCoder_type,MCRYPT_MODE_ECB), MCRYPT_RAND);
$decrypted_string = mcrypt_decrypt( $EnCoder_type, $EnCoder_Key, trim($string_en), MCRYPT_MODE_CBC, $iv);
return trim($decrypted_string);
}
function hex2bin($hexdata) {
for ($i=0;$i<strlen($hexdata);$i+=2) {
$bindata.=chr(hexdec(substr($hexdata,$i,2)));
}
return $bindata;
}
?>
得到的结果~~
Array
(
[0] => 53b919490432e7037e544ad5af0e1f68b42a5a73dd00ba68b878f6601ccca8b8
[1] => 5b9f4e6040cc46ecd9f012a326d711baf9886e9051ad10021c320ec87c32920b
[2] => ec359b112ed26fd78458e6644a329e0ab262c2f011ea935e7b872f355db4e01b
[3] => 23971d0d5896bc7976c2e48b02664984e8fa12f9fc1549342f352f06e212787b
[4] => b353aa1c6abcde8931b145ec56d79e0ec08cd733c6305b279b56417229bcb8ac
)
Array
(
[0] => j磈ゃI?
哚y$a疾呼
[1] => 韭馑=鋘莿(?櫍`?`艵阒?? [2] => ?1毩g检簖G梾w宓拿夥咽迪址椒? [3] => 嵏o?氦)徱堣支持附件(多个),
[4] => 悯緭)o梈?斞遡f?如果您还没有
)
为什么这样啊??
望高手指点!~~~