解密错误:要解密的数据长度无效

时间:2016-09-12 09:15:55

标签: c# asp.net rijndael

我用这段代码来解密我的文件,但是我收到了这个错误:

  

解密错误:要解密的数据长度无效

我的代码:

private void DecryptFile(string inputFile, string outputFile)
{
    //try
    //{
    string password = @"myKey123"; // Your Key Here

    UnicodeEncoding UE = new UnicodeEncoding();
    byte[] key = UE.GetBytes(password);

    FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);

    RijndaelManaged RMCrypto = new RijndaelManaged();

    CryptoStream cs = new CryptoStream(fsCrypt,
        RMCrypto.CreateDecryptor(key, key),
        CryptoStreamMode.Read);

    FileStream fsOut = new FileStream(outputFile, FileMode.Create);

    int data;
    while ((data = cs.ReadByte()) != -1)
        fsOut.WriteByte((byte)data);

    fsOut.Close();
    cs.Close();
    fsCrypt.Close();

    //}
    //catch
    //{
    //    Label12.Text = "Decryption failed!";
    //}
}

它在c#应用程序中运行良好,但我在asp.net页面中有错误!

0 个答案:

没有答案