我在这个MSDN页看很好的例子:http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.aspxMSDN例子:这是一个错误或优化(X509Certificate2类)
向下滚动半路上的例子,并期待进入方法:
// Decrypt a file using a private key.
private static void DecryptFile(string inFile, RSACryptoServiceProvider rsaPrivateKey)
你会发现读者在时间只读取3个字节,而它正试图读取一个int的料流:
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
由于下一行是寻求ŧ o位置“4”,错误被掩盖。我是否正确,或者是否有意为之,即某种奇怪的优化,因为我们知道(对于这个例子)AES密钥和IV的长度将足够小以容纳3字节,所以只读3,然后跳过到4,从而节省读取1个字节的磁盘?
如果优化....真的吗?