Results 1 to 2 of 2

Thread: [RESOLVED] Getting Hash of File in VB.net -- Code does not produce same hash as certutil.exe

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2014
    Posts
    63

    Resolved [RESOLVED] Getting Hash of File in VB.net -- Code does not produce same hash as certutil.exe

    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
    Last edited by walt4; May 9th, 2021 at 10:05 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width