我有以下生成密钥的c#代码:
public static byte[] Encrypt(byte[] plainData,string salt) { DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); DES.Key = ASCIIEncoding.ASCII.GetBytes(salt); DES.IV = ASCIIEncoding.ASCII.GetBytes(salt); ICryptoTransform desencrypt = DES.CreateEncryptor(); byte[] encryptedData = desencrypt.TransformFinalBlock(plainData,plainData.Length); return encryptedData; } private string GetEncryptedKey(string key) { return BitConverter.ToString(KeyGeneratorForm.Encrypt(ASCIIEncoding.ASCII.GetBytes(key),"abcdefgh")).Replace("-",""); }
function get_encrypted_key($key){ $salt = "abcdefgh"; return bin2hex(mcrypt_encrypt(MCRYPT_DES,$salt,$key,MCRYPT_MODE_CBC,$salt)); }
但是,结果中存在小的差异,因为最后16个字符总是不同的:@H_301_4@
With key "Benjamin Franklin": C# : 0B3C6E5DF5D747FB3C50DE952FECE3999768F35B890BC391 PHP: 0B3C6E5DF5D747FB3C50DE952FECE3993A881F9AF348C64D With key "President Franklin D Roosevelt": C# : C119B50A5A7F8C905A86A43F5694B4D7DD1E8D0577F1CEB32A86FABCEA5711E1 PHP: C119B50A5A7F8C905A86A43F5694B4D7DD1E8D0577F1CEB37ACBE60BB1D21F3F
我还尝试使用以下代码对我的密钥执行填充转换:@H_301_4@
function get_encrypted_key($key){ $salt = "abcdefgh"; $extra = 8 - (strlen($key) % 8); if($extra > 0) { for($i = 0; $i < $extra; $i++) { $key.= "\0"; } } return bin2hex(mcrypt_encrypt(MCRYPT_DES,$salt)); }
但我最终得到的结果与没有填充相同.@H_301_4@
如果你有任何关于发生了什么的线索,我会很高兴听到它! 原文链接:https://www.f2er.com/php/133873.html