填充无效,解密时无法删除 [英] Padding is invalid and cannot be removed while decrypting
问题描述
我正在使用以下代码来解密文本文件。它在while((data = cs.ReadByte())!= -1)行上给出了填充无效且无法删除的异常。 br $>
private void Decrypt(string inputFilePath,string outputfilePath)
{
string EncryptionKey =MAKV2SPBNI99212; <使用(Aes encryptor = Aes.Create())
$ / b
$
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
使用(FileStream fsInput = new FileStream(inputFilePath,FileMode.Open))
{
使用(CryptoStream cs = new CryptoStream(fsInput,encryptor.CreateDecryptor(),CryptoStreamMode.Read)) $
int data ;
while((data = cs.ReadByte())!= -1)
{
fsOutput.WriteByte((byte)data );
}
}
}
}
}
}
如何解决?
I am using following code to decrypt a text file.It gives me exception on "Padding is invalid and cannot be removed" on "while ((data = cs.ReadByte()) != -1)" line.
private void Decrypt(string inputFilePath, string outputfilePath)
{
string EncryptionKey = "MAKV2SPBNI99212";
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (FileStream fsInput = new FileStream(inputFilePath, FileMode.Open))
{
using (CryptoStream cs = new CryptoStream(fsInput, encryptor.CreateDecryptor(), CryptoStreamMode.Read))
{
using (FileStream fsOutput = new FileStream(outputfilePath, FileMode.Create))
{
int data;
while ((data = cs.ReadByte()) != -1)
{
fsOutput.WriteByte((byte)data);
}
}
}
}
}
}
How to solve it?
推荐答案
这篇关于填充无效,解密时无法删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!