わかりました、これは奇妙です、私にとって。私はこのコードを持っています。
using (MemoryStream memStream = new MemoryStream(inBytes))
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
using (CryptoStream cs = new CryptoStream(memStream, decryptor, CryptoStreamMode.Read))
{
byte[] buffer;
if (inBytes.Length < (1024 * 10)) buffer = new byte[inBytes.Length];
else buffer = new byte[(1024 * 10)];
long readBytes = 0;
long totalBytes = inStream.Length;
int currBytes;
while (readBytes < totalBytes)
{
currBytes = cs.Read(buffer, 0, buffer.Length);
fs.Write(buffer, 0, currBytes);
readBytes += currBytes;
}
}
これにより、復号化されたデータがファイルに書き込まれます。
次に、 a に書き込む(および返す)ことを除いて、まったく同じことを行う次のコードがありますMemoryStream。
using(MemoryStream memStream = new MemoryStream(inBytes))
using(MemoryStream ms = new MemoryStream())
using (CryptoStream cs = new CryptoStream(memStream, decryptor, CryptoStreamMode.Read))
{
byte[] buffer;
if (inBytes.Length < (1024 * 10)) buffer = new byte[inBytes.Length];
else buffer = new byte[(1024 * 10)];
long readBytes = 0;
long totalBytes = inStream.Length;
int currBytes;
while (readBytes < totalBytes)
{
currBytes = cs.Read(buffer, 0, buffer.Length);
ms.Write(buffer, 0, currBytes);
readBytes += currBytes;
}
return ms;
}
行currBytes = cs.Read(buffer, 0, buffer.Length)で「復号化するデータの長さが無効です」というエラーが表示されますが、最初ではなく2番目のセットでのみ発生します。「ICryptoTransformデクリプター」は一般的な方法で作成されており、同じキーを使用していることはわかっています。
最初のインスタンスではこのエラーが発生しないのに、2 番目のインスタンスではエラーが発生する理由と、(さらに重要なことに) 修正方法を教えてください。
そして、はい、DES がこれまでで最高の暗号化方式ではないことはわかっています。これは、実稼働環境で日の目を見ることのない概念実証の性質のものです。