解密加密的CSV文件并将其保存到byteArray中

时间:2014-01-16 07:02:16

标签: c# csv encryption

下面的代码收到错误消息“要解密的数据长度无效。” 当我尝试将其复制到MemoryStream时。我该如何解决这个问题?

var table = (Encoding.Default.GetString(result, 0, result.Length - 1))
    .Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
MemoryStream encryptedStream = new MemoryStream();
encryptedStream.Write(result, 0, filelength);     

DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
ICryptoTransform desdecrypt = DES.CreateDecryptor();          

MemoryStream decryptedStream = new MemoryStream();
encryptedStream.Position = 0;
CryptoStream decryptStream = new CryptoStream(encryptedStream, desdecrypt,
    CryptoStreamMode.Read);
decryptStream.CopyTo(decryptedStream);
decryptedStream.Position = 0;

0 个答案:

没有答案