【发布时间】:2021-03-15 18:25:32
【问题描述】:
在提供商以十六进制格式发送给我的 TRIPLEDES 中执行解密时遇到问题:EF69FF79BBD7E8E4EF69FF79BBD7E8E4,使用以下密钥“0123456789ABCDEFFEDCBA9876543210”,应用以下方法:
public IActionResult GetTokenTemp1()
{
TripleDESCryptoServiceProvider tDESalg = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
tDESalg.Key = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes("0123456789ABCDEFFEDCBA9876543210"));
byte[] cipherBytes = Convert.FromBase64String("EF69FF79BBD7E8E4EF69FF79BBD7E8E4");
string finalDecrypt = _3desTest.DecryptTextFromMemory(cipherBytes, tDESalg.Key, tDESalg.IV);
return Ok(finalDecrypt);
}
public static string DecryptTextFromMemory(byte[] Data, byte[] Key, byte[] IV)
{
try
{
// Create a new MemoryStream using the passed
// array of encrypted data.
MemoryStream msDecrypt = new MemoryStream(Data);
TripleDESCryptoServiceProvider de = new TripleDESCryptoServiceProvider();
var descritor = de.CreateDecryptor(Key, IV);
// Create a CryptoStream using the MemoryStream
// and the passed key and initialization vector (IV).
CryptoStream csDecrypt = new CryptoStream(msDecrypt,
descritor,
CryptoStreamMode.Read);
// Create buffer to hold the decrypted data.
byte[] fromEncrypt = new byte[Data.Length];
// Read the decrypted data out of the crypto stream
// and place it into the temporary buffer.
csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
string es = new UTF8Encoding().GetString(fromEncrypt);
//Convert the buffer into a string and return it.
return new UTF8Encoding().GetString(fromEncrypt);
}
catch (CryptographicException e)
{
Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
return null;
}
}
当我将默认填充或任何其他设置为零或无时,我收到以下错误“添加无效且无法删除。”,
但是当我将填充设置为零或无 tripleDescryptorService.Padding = PaddingMode.None 时,我得到了一个格式:
padding.none
当我在这个页面上做时,我不知道该怎么做: https://neapay.com/online-tools/des-calculator.html?data=EF69FF79BBD7E8E4EF69FF79BBD7E8E4&key=0123456789ABCDEFFEDCBA9876543210&algo=3DES&decr=true
我得到了想要的结果。
我已经绝望了,我不是很擅长加密。
非常感谢
【问题讨论】:
-
正如您已经写过“以十六进制发送给我”的那样,我在您的代码中缺少“十六进制字符串到二进制/字节数组函数”。同样,我看不到您的代码中的“IV”来自何处,因此请编辑您的问题并发布一个最小但完整的代码示例,谢谢。
-
对不起,我已经编辑过了
标签: c# .net asp.net-core-3.1 tripledes