Use the HMACSHA1 hashing function to generate a checksum for a file. : File Utilities « Stream File « VB.Net Tutorial






Imports System.Text
Imports System.Security.Cryptography

Public Class Tester
    Public Shared Sub Main
        Dim checksum1 As Byte()
        checksum1 = GenerateFileChecksum("test.txt")
    End Sub

    Public Shared Function GenerateFileChecksum(ByVal filePath As String) As Byte()
        Dim hashingFunction As HMACSHA1
        Dim hasingBase() As Byte
        Dim hashValue() As Byte
        Dim inStream As IO.Stream

        If (My.Computer.FileSystem.FileExists(filePath)= False) Then
            Throw New IO.FileNotFoundException
            Return Nothing
        End If

        hasingBase = (New UnicodeEncoding).GetBytes("Cookbook")
        hashingFunction = New HMACSHA1(hasingBase, True)

        inStream = New IO.FileStream(filePath,IO.FileMode.Open, IO.FileAccess.Read)
        hashValue = hashingFunction.ComputeHash(inStream)
        inStream.Close()
        Return hashValue
    End Function

End Class








13.3.File Utilities
13.3.1.Copy a file
13.3.2.Use the HMACSHA1 hashing function to generate a checksum for a file.
13.3.3.Delete a file with kill
13.3.4.Delete a file
13.3.5.File copyFile copy
13.3.6.Move a File
13.3.7.Move a file with File.Move
13.3.8.Use FreeFile
13.3.9.Use FreeFile to read a text file