我在使用 CryptoStream 进行文件加密时遇到了麻烦。
代码:
public static void EncryptFile(string inputFile, string outputFile)
{
int num;
string s = "PUPlr";
byte[] bytes = new UnicodeEncoding().GetBytes(s);
string path = outputFile;
FileStream stream = new FileStream(path, FileMode.Create);
RijndaelManaged managed = new RijndaelManaged();
CryptoStream crpytStream = new CryptoStream(stream, managed.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);
FileStream stream2 = new FileStream(inputFile, FileMode.Open);
while ((num = stream2.ReadByte()) != -1)
{
crpytStream.WriteByte((byte)num);
}
stream2.Close();
crpytStream.Close();
stream.Close();
}
尝试“managed.BlockSize = 16;” 或“= 128;” 似乎不起作用,那么我该如何解决我的错误?