C# 中的 TripleDES,与工具的值不同
TripleDES in C#, not the same value with tool
在一个网页中使用在线工具用三重 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);}}
有人知道为什么吗?
借助 class 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);
它returns 相同的输出。 3A-A4-CC-DE-E3-F7-53-A3-CE-62-B7-22-52-38-68-73
在一个网页中使用在线工具用三重 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);}}
有人知道为什么吗?
借助 class 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);
它returns 相同的输出。 3A-A4-CC-DE-E3-F7-53-A3-CE-62-B7-22-52-38-68-73