ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 29th, 2005, 12:59 PM
WeBoat WeBoat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 61 WeBoat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 5 m 43 sec
Reputation Power: 5
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
Attached Images
File Type: jpg 1.jpg (61.8 KB, 139 views)
File Type: jpg 2.jpg (13.2 KB, 197 views)
Attached Files
File Type: zip validatefile.zip (1.2 KB, 255 views)
File Type: zip CFX_HASH.zip (90.2 KB, 220 views)

Reply With Quote
  #2  
Old January 29th, 2005, 01:06 PM
WeBoat WeBoat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 61 WeBoat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 5 m 43 sec
Reputation Power: 5
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Bug in CFX_HASH? 2 files, same hash.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT