在那里我需要获取文件的哈希值。对于那部分,我正在使用以下代码。
'Open file
Dim fs As FileStream = New FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, 8)
'Get the size we need for our hash.
Dim fileHandle As IntPtr = fs.SafeFileHandle.DangerousGetHandle()
Dim hashSize As Integer
Dim hash As Byte() = New Byte(256) {}
Dim b As Boolean = CryptCATAdminCalcHashFromFileHandle(fileHandle, hashSize, Nothing, 0)
'check results
System.Console.WriteLine(fileHandle)
System.Console.WriteLine(hashSize)
System.Console.WriteLine(hash)
System.Console.WriteLine(b)
使用 wintrust.dll 如下
<DllImport("Wintrust.dll", PreserveSig:=True, SetLastError:=False)> _
Private Shared Function CryptCATAdminCalcHashFromFileHandle(ByRef fileHandle As IntPtr, ByVal hash As IntPtr, ByVal hashSize As Byte(), ByVal dwFlags As Integer) As Boolean
End Function
文件句柄的输出在不同的执行中获得不同的值(这没关系)但是哈希大小和哈希始终为零。b 总是假的。
我在这里错过了什么吗?请指教