|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Bug in CFX_HASH? 2 files, same hash.
I've been playing with CFX_HASH today. Very strangely, two of the first files I've tried with it are returning the same hash.
1.jpg size: 62KB. 2.jpg size 14kb. Here is what my test code is returning: File 1: C:\\webs\\officex3\\hash\\1.jpg File 2: C:\\webs\\officex3\\hash\\2.jpg Hash Algorithm: SHA Hash of File 1: 30567F6B52AF60449A6113D3C80FB9F850B7426A Hash of File 2: 30567F6B52AF60449A6113D3C80FB9F850B7426A These Files are Identical to one another Here is the test code: <!-- This test uses the CFX_HASH tag in conjunction with CFFILE to calculate a message digest of a file. This digest can then be compared to digests computed against other copies of the file to verify that the files are identical. --> <!-- Begin with some defines --> <CFSET #Path# = "C:\\webs\\officex3\\hash\\"> <CFSET #FileName1# = #Path# & "1.jpg"> <CFSET #FileName2# = #Path# & "2.jpg"> <CFPARAM Name="Cipher" Default="SHA"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML> <HEAD> <TITLE>Using CFX_HASH in Document Verification Applications</TITLE> </HEAD> <BODY BGCOLOR=FFFFFF> <CENTER> <TABLE CELLPADDING=10 VALIGN="TOP"> <TR><TD COLSPAN=2><FONT FACE="Arial,Helvetica" SIZE=-1> This demonstration uses the CFX_HASH tag in conjunction with CFFILE to calculate a digital "fingerprint" of a file. The technique used here makes use of the <CFFILE Action=READ Variable=MyVar> command in Cold Fusion. Here we read the contents of a file into a CF Variable, and then process that variable in CFX_HASH. The resulting digest can then be compared to the message digests generated against other copies of the file to verify that the files are identical. <P>Note that if you calculate the message digest of identical files, you should get the same results. In this case, we are comparing the message digest of two identical files, so the resulting digital fingerprints should be identical. </FONT> <!------------------ TEST Identical FILES -------------------------> <CFOUTPUT> <PRE> File 1: <B><A HREF="#FileName1#">#FileName1#</A></B> File 2: <B><A HREF="#FileName2#">#FileName2#</A></B> Hash Algorithm: <B>#Cipher#</B> </PRE> </CFOUTPUT> <!--- Read the files with CFFILE ---> <CFFILE ACTION="READ" FILE="#FileName1#" VARIABLE="ContentsA"> <CFFILE ACTION="READ" FILE="#FileName2#" VARIABLE="ContentsB"> <!--- Compute Message Digests of the files ---> <CFX_HASH CIPHER=#Cipher# InputString=#ContentsA# VARIABLE="Hash1"> <CFX_HASH CIPHER=#Cipher# InputString=#ContentsB# VARIABLE="Hash2"> <!--- Compare the Digests ---> <CFIF #Hash1# eq #Hash2# > <CFSET #MSG# = "These Files are Identical to one another" > <CFELSE> <CFSET #MSG# = "These Files are NOT Identical to one another" > </CFIF> <FONT FACE="Arial,Helvetica" SIZE=-1><CFOUTPUT> Hash of File 1: #Hash1# <BR>Hash of File 2: #Hash2# <P><B>#MSG#</B> </CFOUTPUT> </FONT> </TD> </TR> </TABLE> </CENTER> These two files return the same hash for SHA or MD5 hashes. Other files seem to work fine. I am also going to attach the applicable files including a zip of CFX_HASH.DLL. Am I doing something wrong? I thought this was not possible. Thanks Tim |
|
#2
|
|||
|
|||
|
I thought the following would fix it, but this just causes another problem:
It's in the CF_FILE statments. Images have to be read in binary mode: <!--- Read the files with CFFILE ---> <CFFILE ACTION="READBINARY" FILE="#FileName1#" VARIABLE="ContentsA"> <CFFILE ACTION="READBINARY" FILE="#FileName2#" VARIABLE="ContentsB"> Now if I have two identical files, (I copied 1.jpg to 3.jpg and set that as my two files), it says they are NOT identical. If a file is copied into different filenames, would it return a different hash? This is very confusing. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Bug in CFX_HASH? 2 files, same hash. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|