首頁  >  文章  >  後端開發  >  c# des 加密如何转换成php实现

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

WBOY
WBOY原創
2016-06-02 11:28:261150瀏覽

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn