Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

crc check?

Status
Not open for further replies.

Sidro

MIS
Sep 28, 2002
197
US
hi,
I was wondering if anyone knows how to do this. I have a couple of files that I would like to keep it from being tampered with.For example I dont want people to change or edit the content of the files. Anyone know how to dod a crc check on a file to see if the files been tampered with?
Thankx in advance.
 
I am not going to post a CRC calculation algorithm here but something similar to it already built in Windows.

It is the HashData function exported by Shell Light-weight API Library (shlwapi.dll).

This function hashes a stream of data passed to it. The length of the requested hash data may range from 1 to 255 bytes.

In the code below the file whose hash is requested is opened in binary mode and its data is passed to this function as a byte array. This function fills a 4-byte hash value in the return value of the function. This 4-byte long value is dependent on the contents of the file and will change even if you change a single bit in the contents of the file. You can use this value to keep track of any change made to a file.
---

Private Declare Sub HashData Lib "shlwapi" (pbData As Any, ByVal cbData As Long, pbHash As Any, ByVal cbHash As Long)

Private Function HashFile(FileName As String) As Long
Dim FN As Integer, Bytes() As Byte
FN = FreeFile
Open FileName For Binary Access Read As #FN
ReDim Bytes(1 To LOF(FN))
Get #FN, , Bytes
Close #FN
HashData Bytes(1), UBound(Bytes), HashFile, 4
End Function

Private Sub Form_Load()
MsgBox Hex$(HashFile("C:\autoexec.bat"))
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top