【发布时间】:2012-02-22 04:21:25
【问题描述】:
我正在查看此 MSDN 页面中的好示例:http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.aspx
向下滚动到示例的一半并查看方法:
// Decrypt a file using a private key.
private static void DecryptFile(string inFile, RSACryptoServiceProvider rsaPrivateKey)
您会注意到阅读器在尝试从流中读取 int 时,一次只读取 3 个字节:
inFs.Seek(0, SeekOrigin.Begin);
inFs.Read(LenK, 0, 3);// <---- this should be 4
inFs.Seek(4, SeekOrigin.Begin);// <--- this line masks the bug for smaller ints
inFs.Read(LenIV, 0, 3); // <---- this should be 4
由于下一行是寻找位置“4”,因此该错误被掩盖了。我是对的还是故意的,即某种奇怪的优化,因为我们知道(对于这个例子)AES Key 和 IV 的长度将小到可以容纳在 3 个字节中,所以只读 3 然后跳过到 4,从而节省从磁盘读取 1 个字节?
如果优化......真的吗??
【问题讨论】: