CryptoStream产生零字节数据

时间:2012-04-20 13:49:55

标签: c# cryptography

下面的代码有什么问题? CryptoStream生成零字节数据。

public void Decrypt(Stream theInput, Stream theOutput, string theKey)
{
    Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(theKey, salt);
    RijndaelManaged RM = new RijndaelManaged();
    RM.Mode = CipherMode.ECB;

    using (CryptoStream cs = new CryptoStream(theOutput, RM.CreateDecryptor(pdb.GetBytes(32), pdb.GetBytes(16)), CryptoStreamMode.Write))
    {
        int bufferLen = 4096;
        byte[] buffer = new byte[bufferLen];
        int bytesRead;
        do
        {
            bytesRead = theInput.Read(buffer, 0, bufferLen);
            cs.Write(buffer, 0, bytesRead);
        } while (bytesRead != 0);
    }
}

0 个答案:

没有答案