加密phpc#
c#-------------
私有字符串 DES3Encrypt(字符串数据, 字符串密钥, 字符串 iv){
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
DES.Key = ASCIIEncoding.ASCII.GetBytes(key);
DES.IV = ASCIIEncoding.ASCII.GetBytes(iv);
DES.Mode = CipherMode.CBC;
DES.Padding = PaddingMode.PKCS7;
ICryptoTransform DESEncrypt = DES.CreateEncryptor();
byte[] Buffer = ASCIIEncoding.ASCII.GetBytes(data);
return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer) , 0, Buffer.Length));
}
php------------
公共静态函数 des($key,$iv,$str){
$len = strlen($str);
$str = self::pkcs7_pad($str, $len);
$td = mcrypt_module_open('tripledes', '', 'ecb', ' ');
mcrypt_generic_init($td, $key, $iv);
$encrypted_data = mcrypt_generic($td, $str);
mcrypt_generic_deinit($td);
mcrypt_module_close($td) ;
返回base64_encode($encrypted_data);
}
公共静态函数pkcs7_pad($text,$blocksize){
$pad = $blocksize - (strlen($text) % $blocksize);
返回 $text 。 str_repeat(chr($pad), $pad);
}
php加密后的字符串不对,问哪有问题?