我需要解密在 OFB 模式下使用 3DES 加密的消息。
我有一个加密的消息。我有一把钥匙。我有静脉注射。
我在.Net平台上
加密消息在 base64 中为 24 个字符长。密钥在 base64 中为 24 个字符长。IV 是一个 64 位的二进制数。
由于缺乏示例我尝试使用ECB模式示例,如下:
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);
// Create a CryptoStream using the MemoryStream
// and the passed key and initialization vector (IV).
CryptoStream csDecrypt = new CryptoStream(msDecrypt,
new TripleDESCryptoServiceProvider().CreateDecryptor(Key, IV),
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);
//Convert the buffer into a string and return it.
return new ASCIIEncoding().GetString(fromEncrypt);
}
catch (CryptographicException e)
{
Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
return null;
}
}
这是我得到的错误:
发生加密错误:指定的密钥不是此算法的有效大小。
我尝试了其他代码示例,其中我将算法更改为 OFB,但它说它不受支持。
谁能帮帮我吗?我显然对这些东西不够了解,所以如果我搞砸了一些明显的事情,请耐心等待。
在 ECB 模式中有大量 3DES 解密的示例,但我几乎找不到关于 OFB 模式的信息。