<?php
$key = "thisiskey";
function encrypt($encrypt) {
global $key;
$encrypt = pkcs5_pad($encrypt);
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_DES, MCRYPT_MODE_CBC), MCRYPT_RAND);
$passcrypt = mcrypt_encrypt(MCRYPT_DES, $key, $encrypt, MCRYPT_MODE_CBC, $iv);
$encode = base64_encode($passcrypt);
return $encode;
//return bin2hex($passcrypt);
}
function pkcs5_pad($text)
{
$len = strlen($text);
$mod = $len % 8;
$pad = 8 - $mod;
return $text.str_repeat(chr($pad),$pad);
}
echo encrypt('thisistext');
exit;
运行结果是 VX2gnZbjSLVU5an1Z97GIw==
但是最后结果跟
http://www.tero.co.uk/des/code.php 上的des加密算法输出不一样
用tero这个网址所用的代码运行
<?php
error_reporting(E_ALL ^E_NOTICE);
$key = "thisiskey";
$message = "thisistext";
$ciphertext = des ($key, $message, 1, 0, null,'');
echo "DES Test Encrypted: " . base64_encode ($ciphertext);
结果 是 DES Test Encrypted: PzsmwkLug7E0Me2iHC+LHg==
有没有高手来看一下问题出在哪里?