0
我下面的檢查文件的數字簽名的代碼文件的哈希在Sysinternals計算使用CryptCATAdminCalcHashFromFileHandle在VB
在那裏,我需要得到一個文件的哈希值。對於那部分我使用下面的代碼。
'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
輸出的文件句柄獲取不同執行不同的值(這是確定) 但HASHSIZE和哈希始終是零。而b總是假的。
我在這裏錯過了什麼。 請指點
你的VB仍然有pollish,因爲這似乎正確= P。優秀。 – WhozCraig
我不知道該如何謝謝你。我幾個小時都在苦苦掙扎。從未想過將ByRef更改爲ByVal for fileHandle。再次感謝arx。 –