Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Checksum of a file ...

Posted on 2009-07-13
9
Medium Priority
?
366 Views
Last Modified: 2012-05-07
I need to check whether a file is tampered or not by checking its checksum. If the checksums does not match the file is tampered!

I googled and have found plenty of codes but none of them tells me how to compare the original and tampered checksum! They only returns current checksum of the file.

Any help would be appreciated

Thank you

Regards
Raj
0
Comment
Question by:krisrajz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 13

Expert Comment

by:game-master
ID: 24838359
Here is some checksum code... fer ya
 

Option Explicit
Option Compare Text
 
'// Then declare this array variable Crc32Table
Private Crc32Table(255) As Long
 
'// Getting a checksum
'x'Public Sub Main()
'x' Dim lCrc32Value As Long
'x' On Error Resume Next
'x' lCrc32Value = InitCrc32()
'x' lCrc32Value = AddCrc32("This is the original message!", lCrc32Value)
'x' Debug.Print Hex$(GetCrc32(lCrc32Value))
'x'End Sub
 
 
Public Function InitCrc32(Optional ByVal Seed As Long = &HEDB88320, Optional ByVal Precondition As Long = &HFFFFFFFF) As Long
'// Declare counter variable iBytes, counter variable iBits, value variables lCrc32 and lTempCrc32
Dim iBytes As Integer, iBits As Integer, lCrc32 As Long, lTempCrc32 As Long
 
'// Turn on error trapping
On Error Resume Next
'// Iterate 256 times
For iBytes = 0 To 255
'// Initiate lCrc32 to counter variable
lCrc32 = iBytes
'// Now iterate through each bit in counter byte
For iBits = 0 To 7
'// Right shift unsigned long 1 bit
lTempCrc32 = lCrc32 And &HFFFFFFFE
lTempCrc32 = lTempCrc32 \ &H2
lTempCrc32 = lTempCrc32 And &H7FFFFFFF
 
'// Now check if temporary is less than zero and then mix Crc32 checksum with Seed value
If (lCrc32 And &H1) <> 0 Then
lCrc32 = lTempCrc32 Xor Seed
Else
lCrc32 = lTempCrc32
End If
Next
'// Put Crc32 checksum value in the holding array
Crc32Table(iBytes) = lCrc32
Next
'// After this is done, set function value to the precondition value
InitCrc32 = Precondition
End Function
 
 
Public Function AddCrc32(ByVal Item As String, ByVal Crc32 As Long) As Long
'// Declare following variables
Dim bCharValue As Byte, iCounter As Integer, lIndex As Long
Dim lAccValue As Long, lTableValue As Long
 
'// Turn on error trapping
On Error Resume Next
'// Iterate through the string that is to be checksum-computed
For iCounter = 1 To Len(Item)
'// Get ASCII value for the current character
bCharValue = Asc(Mid$(Item, iCounter, 1))
'// Right shift an Unsigned Long 8 bits
lAccValue = Crc32 And &HFFFFFF00
lAccValue = lAccValue \ &H100
lAccValue = lAccValue And &HFFFFFF
'// Now select the right adding value from the holding table
lIndex = Crc32 And &HFF
lIndex = lIndex Xor bCharValue
lTableValue = Crc32Table(lIndex)
'// Then mix new Crc32 value with previous accumulated Crc32 value
Crc32 = lAccValue Xor lTableValue
Next
'// Set function value the the new Crc32 checksum
AddCrc32 = Crc32
End Function
 
 
Public Function GetCrc32(ByVal Crc32 As Long) As Long
'// Turn on error trapping
On Error Resume Next
'// Set function to the current Crc32 value
GetCrc32 = Crc32 Xor &HFFFFFFFF
End Function
 
 
'// And for testing the routines above...
Public Sub Main()
Dim lCrc32Value As Long
On Error Resume Next
lCrc32Value = InitCrc32()
lCrc32Value = AddCrc32("This is the original message!", lCrc32Value)
Debug.Print Hex$(GetCrc32(lCrc32Value))
End Sub
 
 
Public Function TapCrc(buf As String) As Long
Dim l&, i
l& = 0
For i = 1 To Len(buf)
l& = l& + Asc(Mid(buf, i, 1))
Next
TapCrc = l&
End Function

Open in new window

0
 
LVL 20

Expert Comment

by:hes
ID: 24842119
You are going to have to save the origional checksum in the program somewhere, then compare the current with that. If they are not the same it has been tampered with
0
 
LVL 1

Author Comment

by:krisrajz
ID: 24856121
Application written in VB need to check the checksum of a file. The checksum is not stored in the file. If the old checksum and the new checksum does not match, the file is tampered. How to get the old and the new checksum?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Expert Comment

by:game-master
ID: 24856245


HAVE U TRIED THE ONE I HAVE POSTED...



game-master
0
 
LVL 1

Author Comment

by:krisrajz
ID: 24856257
Hi game-mater,
I already have some piece of code to get the checksum of data and file ... all I need is to get the old and the new checksum!

Raj
0
 
LVL 46

Accepted Solution

by:
aikimark earned 60 total points
ID: 24857599
@Raj

1. Save lines of checksum and path\filename pairs in a file.
2. When your program starts, read these lines into a dictionary object with the checksum being the data and the path\filename being the key.
3. As you look at the current state of files, use the path\filename to retrieve the old checksum for comparison.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 24903334
I object to the question deletion requestion.  "ok" is not a valid reason to request a question be deleted.

Moreover, I think the posted comments have answered the question.
0
 
LVL 1

Author Closing Comment

by:krisrajz
ID: 31602745
Great
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question