c# des 加密如何转换成php实现
c#-------------
private string DES3Encrypt(string data, string key, string 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------------
public static function 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);
return base64_encode($encrypted_data);
}
public static function pkcs7_pad($text,$blocksize){
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
php加密后的串不对,问哪有问题?