【发布时间】:2015-03-21 17:43:52
【问题描述】:
我正在编写一个加密程序来加密文件(大小)来做到这一点,我目前的方法是从文件中读取 1024 个字节,加密这些字节,并将它们写入临时文件,然后重复直到完成.此过程完成后,将删除原始文件并将临时文件重命名为原始文件的名称。
这是一段处理 n 字节(n 为 1024)的示例代码:
private void processChunk(BinaryReader Input, BinaryWriter Output, int n)
{
// Read n bytes from the input fileStream
Byte[] Data = Input.ReadBytes(n);
// Read n bytes from the streamCipher
Byte[] cipherData = StreamCipher.OutputBytes(n);
for (int x = 0; x < n; x++)
// XOR a byte of the input stream with a corresponding byte of the streamCipher
Data[x] ^= cipherData[x];
// Write n bytes to the output fileStream
Output.Write(Data);
}
所以我很确定我不能对加密算法进行多线程处理,因为字节是作为密钥流生成的,并且取决于之前生成的字节,但是从文件和 cpu 操作中读取和写入可以吗?
最好的策略是什么?
【问题讨论】:
-
为什么不使用现有的加密算法?
-
因为我非常喜欢信息安全的职业,我想了解加密的本质及其应用。这段代码是我的 a-level 课程的一部分 :)
标签: c# wpf multithreading encryption