VB.Net如何获得Assembly Checksum(SHA1,MD5,SHA256,SHA512)的值?

时间:2017-08-28 06:17:00

标签: vb.net hash

如何在vb.net中获取SHA1,SHA256,SHA512,MD5校验和值?

我可以从像Hasher这样的第三方实用程序中获取我的exe文件校验和值... 但是我想获得自己的汇编校验和值?

请帮助

更新:1我试过自己

       Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim _myexe$
    Try
        _myexe$ = IO.Path.Combine(My.Application.Info.DirectoryPath, My.Application.Info.AssemblyName & ".exe")
        Using _sha512 As New System.Security.Cryptography.SHA512CryptoServiceProvider
            Using stream = File.OpenRead(_myexe$)
                Dim _hash = _sha512.ComputeHash(stream)
                Trace.WriteLine(BitConverter.ToString(_hash).Replace("-", String.Empty))
            End Using
        End Using
    Catch ex As Exception
        Trace.WriteLine(Err.Description)
    End Try
End Sub

这是获取当前(正在运行)程序集的校验和值的正确方法吗?

1 个答案:

答案 0 :(得分:1)

使用System.Security.Cryptography.MD5

Using md5Hash = MD5.Create()
    Using stream = File.OpenRead(filename) ' file name is your assembly
        Return md5Hash .ComputeHash(stream)
    End Using
End Using