暗号化されたテキスト ファイルを復号化しようとしているときに奇妙な問題が発生しました。基本的に、.txt ファイルの内容は "this is a test :)" であり、出力を復号化すると "this is a test :" であり、欠落している ")" を見つけます。
これは、ファイルを一度に 1 バイトずつ復号化する場合 (while ループ) には当てはまりませんが、以下のコードを使用すると、上記の問題が発生するようです。
private static void DecryptFile(string inputFile, string outputFile, string skey)
{
RijndaelManaged aes = new RijndaelManaged();
try
{
byte[] key = ASCIIEncoding.UTF8.GetBytes(skey);
byte[] file = File.ReadAllBytes(inputFile);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, aes.CreateDecryptor(key, key), CryptoStreamMode.Write))
{
cs.Write(file, 0, file.Length);
File.WriteAllBytes(outputFile, ms.ToArray());
aes.Clear();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
aes.Clear();
}
}
ずさんなコードを許してください。これは単にテスト目的のためのものです。