在C#.NET中,我想解密一些之前已经被DES算法加密的数据,并且只有一个密钥但没有IV!从流中读取时出现异常。我应该写什么?这是我的代码:
byte[] byaText = new byte[] { 0x91, 0x6e , 0x6e , 0x75, 0x76 , 0xa5 , 0x73 , 0x55 };
byte[] byaKey = new byte[] { 0x9B, 0x43, 0xBF, 0x66, 0x98, 0xDE, 0x67, 0xFB };
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
cryptoProvider.Mode = CipherMode.ECB; // even when remarking this line exception occures
MemoryStream memoryStream = new MemoryStream(byaRes);
ICryptoTransform ict = cryptoProvider.CreateDecryptor(byaKey, byaKey); // even "new byte[] {0,0,0,0,0,0,0,0}" as IV, exception occures
CryptoStream cryptoStream = new CryptoStream(memoryStream,
ict, CryptoStreamMode.Read);
StreamReader reader = new StreamReader(cryptoStream);
string decrypted = reader.ReadToEnd(); // here the exception 'Bad Data' occures