Maison  >  Article  >  développement back-end  >  c# des 加密如何转换成php实现

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

WBOY
WBOYoriginal
2016-06-02 11:28:261150parcourir

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

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn