I am looking to verify the integrity of some files in a VB.net program and have encountered something strange.
Originally, I was using the attached class to produce a hash, but during testing noticed that it does not produce the same hash for any given file as Windows certutil.exe.
Clearly I am missing something. Does anyone know what is missing? Or is there a better way to get the hash of a file in VB.net? I could use a process to run certutil.exe, but would prefer to avoid a process if possible.
Class:
Code:Imports System.Text Imports System.Security.Cryptography Public Class SHA Public Shared Function GenerateSHA512String(ByVal inputString) As String Dim sha512 As SHA512 = SHA512Managed.Create() Dim bytes As Byte() = Encoding.UTF8.GetBytes(inputString) Dim hash As Byte() = sha512.ComputeHash(bytes) Dim stringBuilder As New StringBuilder() For i As Integer = 0 To hash.Length - 1 stringBuilder.Append(hash(i).ToString("X2")) Next Return stringBuilder.ToString() End Function End Class




Reply With Quote
