欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

c# des 加密如何转换成php实现

程序员文章站 2022-06-15 11:01:58
...
加密phpc#

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加密后的串不对,问哪有问题?

相关标签: 加密 php c#