27 lines
927 B
VB.net
27 lines
927 B
VB.net
Imports System.IO
|
|
Imports System.Security.Cryptography
|
|
|
|
Public Class FileEx
|
|
''' <summary>
|
|
''' Reads the file at `FilePath` and computes a SHA256 Hash from its contents
|
|
''' </summary>
|
|
''' <param name="pFilePath"></param>
|
|
''' <returns></returns>
|
|
Public Function GetChecksumFromFileContents(pFilePath As String) As String
|
|
Try
|
|
Using oFileStream = IO.File.OpenRead(pFilePath)
|
|
Using oStream As New BufferedStream(oFileStream, 1200000)
|
|
Dim oChecksum() As Byte = SHA256.Create.ComputeHash(oStream)
|
|
Return BaseUtils.FormatHash(oChecksum)
|
|
End Using
|
|
End Using
|
|
Catch ex As Exception
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
|
|
Public Function GetHashFromFileContents(pFilePath As String) As String
|
|
Return GetChecksumFromFileContents(pFilePath)
|
|
End Function
|
|
End Class
|