1 public static string Encrypt3DES(string a_strString, string a_strKey) 2 { 3 4 TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider(); 5 6 DES.Key = ASCIIEncoding.ASCII.GetBytes(a_strKey); 7 DES.Mode = CipherMode.ECB; 8 ICryptoTransform DESEncrypt = DES.CreateEncryptor(); 9 10 byte[] Buffer = ASCIIEncoding.ASCII.GetBytes(a_strString); 11 12 byte[] Buffer2 = DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length); 13 14 StringBuilder builder = new StringBuilder(Buffer2.Length * 3); 15 foreach (byte num in Buffer2) 16 { 17 builder.Append(Convert.ToString(num, 16).PadLeft(2,'0').PadRight(3,' ')); 18 } 19 20 return builder.ToString().ToUpper().Replace(" ",""); 21 }
这是我的C#代码
我用C#的源码测试的结果:
KEY:123456789012345678901234
明文:1054DASF8ASD4GAS5D1G3A2SD
密文:151217178983A3509F5FD3AB94857A633BA927CE8A5414D1DC29BE05CC94DD5F
然后标准的工具是:
KEY:123456789012345678901234
明文:1054DASF8ASD4GAS5D1G3A2SD
密文:151217178983A3509F5FD3AB94857A633BA927CE8A5414D1AB1359AAD7819BC6
最后面8组数据是不一样的,我工具用的是3DES的EDE3模式,求教了,谢谢
In [11]: u=pyDes.triple_des('123456789012345678901234',pyDes.ECB)
In [23]: u.decrypt(binascii.unhexlify('151217178983A3509F5FD3AB94857A633BA927CE8A5414D1DC29BE05CC94DD5F'))
Out[23]: '1054DASF8ASD4GAS5D1G3A2SD\x07\x07\x07\x07\x07\x07\x07'
In [24]: u.decrypt(binascii.unhexlify('151217178983A3509F5FD3AB94857A633BA927CE8A5414D1AB1359AAD7819BC6'))
Out[24]: '1054DASF8ASD4GAS5D1G3A2SD\x00\x00\x00\x00\x00\x00\x00'
您好,请问这是啥意思- -
没看懂