Attribute VB_Name = "basCRC32File" Option Explicit Option Base 0 ' basCRC32File: Calculates CRC-32 checksum for a file. ' Calls crc32 function in basCRC32. ' Version 1. Published 23 October 2006. '************************* COPYRIGHT NOTICE************************* ' This code was originally written in Visual Basic by David Ireland ' and is copyright (c) 2006 D.I. Management Services Pty Limited, ' all rights reserved. ' You are free to use this code as part of your own applications ' provided you keep this copyright notice intact and acknowledge ' its authorship with the words: ' "Contains security software by David Ireland of ' DI Management Services Pty Ltd ." ' This code may only be used as part of an application. It may ' not be reproduced or distributed separately by any means without ' the express written permission of the author. ' David Ireland and DI Management Services Pty Limited make no ' representations concerning either the merchantability of this ' software or the suitability of this software for any particular ' purpose. It is provided "as is" without express or implied ' warranty of any kind. ' Please forward comments or bug reports to www.di-mgt.com.au. ' The latest version of this source code can be downloaded from ' www.di-mgt.com.au/crypto.html. '****************** END OF COPYRIGHT NOTICE************************* Public Function CRC32Sum(sFileName As String) As String ' Computes the CRC-32 checksum for a file Dim sContents As String Dim lCRC As Long Dim sPad As String sContents = ReadFileIntoString(sFileName) If Len(sContents) = 0 Then Exit Function End If lCRC = crc32(sContents) CRC32Sum = Hex(lCRC) ' Pad to exactly 8 hex digits If Len(CRC32Sum) <> 8 Then sPad = String(8 - Len(CRC32Sum), "0") CRC32Sum = sPad & CRC32Sum End If End Function Private Function ReadFileIntoString(sFilePath As String) As String ' Reads file (if it exists) into a string. Dim strIn As String Dim hFile As Integer ' Check if file exists If Len(Dir(sFilePath)) = 0 Then Exit Function End If hFile = FreeFile Open sFilePath For Binary Access Read As #hFile strIn = Input(LOF(hFile), #hFile) Close #hFile ReadFileIntoString = strIn End Function