在带有工具在线的页面中加密带有三重DES的文本:
Key: 09F15B103BC56A6FA705E71F0850EE6D
IV: 0000000000000000
Text: 9876543210123456FFFFFFFFFFFFFFFF
Encrypted value: 3AA4CCDEE3F753A3CE62B72252386873
在C#中,我有一个代码,但我无法获得相同的值。
public static string Encrypt(string toEncrypt, string _key) {
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
byte[] iv = { 0, 0, 0, 0, 0, 0, 0, 0 };
var CharHex = GetHexFromAscii(toEncrypt);
var input = ParseHex(CharHex);
tdes.IV = iv;
tdes.Mode = CipherMode.CBC;
tdes.Padding = PaddingMode.None;
ICryptoTransform cTransform = tdes.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(input, 0,
input.Length);
tdes.Clear();
var resTemp = Convert.ToBase64String(resultArray, 0, resultArray.Length);}}
有谁知道为什么?
答案 0 :(得分:2)
在班级System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary
的帮助下:
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
byte[] iv = { 0, 0, 0, 0, 0, 0, 0, 0 };
var input = SoapHexBinary.Parse("9876543210123456FFFFFFFFFFFFFFFF").Value;
tdes.IV = iv;
tdes.Key = SoapHexBinary.Parse("09F15B103BC56A6FA705E71F0850EE6D").Value;
tdes.Mode = CipherMode.CBC;
tdes.Padding = PaddingMode.None;
ICryptoTransform cTransform = tdes.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(input, 0, input.Length);
tdes.Clear();
var resTemp = BitConverter.ToString(resultArray, 0, resultArray.Length);
返回相同的输出。 3A-A4-CC-DE-E3-F7-53-A3-CE-62-B7-22-52-38-68-73