Please take a look over the code I’ve founded at http://dotnet-snippets.com/dns/calculate-crc32-hash-from-file-SID587.aspx.
The author of this code is Tim Hartwig. If you want to read more about the code/algorithm, please go here!
' This code have to be included in the header of file Imports System.IO
Public Function GetCRC32(ByVal sFileName As String) As String Try Dim FS As FileStream = New FileStream(sFileName, FileMode.Open, FileAccess.Read, FileShare.Read, 8192) Dim CRC32Result As Integer = &HFFFFFFFF Dim Buffer(4096) As Byte Dim ReadSize As Integer = 4096 Dim Count As Integer = FS.Read(Buffer, 0, ReadSize) Dim CRC32Table(256) As Integer Dim DWPolynomial As Integer = &HEDB88320 Dim DWCRC As Integer Dim i As Integer, j As Integer, n As Integer 'Create CRC32 Table For i = 0 To 255 DWCRC = i For j = 8 To 1 Step -1 If (DWCRC And 1) Then DWCRC = ((DWCRC And &HFFFFFFFE) 2&) And &H7FFFFFFF DWCRC = DWCRC Xor DWPolynomial Else DWCRC = ((DWCRC And &HFFFFFFFE) 2&) And &H7FFFFFFF End If Next j CRC32Table(i) = DWCRC Next i 'Calcualting CRC32 Hash Do While (Count > 0) For i = 0 To Count - 1 n = (CRC32Result And &HFF) Xor Buffer(i) CRC32Result = ((CRC32Result And &HFFFFFF00) &H100) And &HFFFFFF CRC32Result = CRC32Result Xor CRC32Table(n) Next i Count = FS.Read(Buffer, 0, ReadSize) Loop Return Hex(Not (CRC32Result)) Catch ex As Exception Return "" End Try End Function
Leave a Reply