Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Matching md5sum

Guest
May 07, 2010 May 07, 2010

I have a bunch of files with md5 numbers generated from the md5sum unix command.  I thought that I could use the #hash(xFile,"MD5")# function in Coldfusion to match the hashes.  But, it seems the hashes are different.  Is there some different command I can use that will make it so these numbers will match?

--ja

1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 08, 2010 May 08, 2010

It should work. What type of file and what are you passing in for #xFile#?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 08, 2010 May 08, 2010

Here is my code.  I added some extra hoping that maybe it was an encoding type that I had wrong.  But no luck.

<cfset joomlaPROD = "motherJoomla">

<cfquery name="data2"

datasource="#joomlaPROD#">

    select jos_docman.id, `dmname`,

dmdescription, dmfilename

    from jos_docman 

    where dmfilename like 'w-sw7-13.pdf'

    limit 1     

</cfquery>

Output of md5sum from linux: 053f35a9c39ec156c9f1fd8a56fc0d8a  /web/joomla/dmdocuments/w-sw7-13.pdf<br />

<br />

<cfoutput

query="data2">

#dmfilename# --

<cffile action="read" file="/web/joomla/dmdocuments/#dmfilename#" variable="xFile"/>

#hash(xFile,"MD5")# <br />

#hash(xFile,"CFMX_COMPAT")# <br/>

#hash(xFile,"SHA")# <br />

#hash(xFile,"SHA-256")# <br/>

#hash(xFile,"SHA-384")# <br />

#hash(xFile,"SHA-512")# <br/>

#hash(xFile,"MD5","US-ASCII")# <br />

#hash(xFile,"MD5","ISO-8859-1")#<br />

#hash(xFile,"MD5","ISO-8859-2")# <br/>

#hash(xFile,"MD5","ISO-8859-4")# <br />

#hash(xFile,"MD5","ISO-8859-5")#<br />

#hash(xFile,"MD5","ISO-8859-7")# <br/>

#hash(xFile,"MD5","ISO-8859-9")# <br />

#hash(xFile,"MD5","ISO-8859-13")#<br />

#hash(xFile,"MD5","ISO-8859-15")# <br />

#hash(xFile,"MD5","UTF-8")#<br />

#hash(xFile,"MD5","UTF-16")# <br />

#hash(xFile,"MD5","UTF-16BE")#<br />

#hash(xFile,"MD5","UTF-16LE")# <br />

And, here is the output where you can see that even though I have all these encoding types, I don't get a match:
w-sw7-13.pdf -- C85E8606EFF5B1D4919647DC9FD6872C
AA285B3F5B8D7483BB7B5158C9641D9D
2DA518C50835EFB6CA0196CA56BAB17E35338287
8510B7643506426187277ACAE1D687533DC9101594EF168747F4B9A8C7BB4BF6
17EF8A1C0DDFE3704AF24D6C8CF83B2A4919CD4D4013FAB0272B8A7EC2A086E19B3B30440604
CE557BC06E08D2C0B3D4
A66BDAE9D51D967F92EE81B768EC12C957D72E1DA387B606C4FC5388D343BAC62FC59333D8E7
1A132B0E0855923E420273A6557E7265E0860998DF5EEC6BA7A1
7962B30C69BE38315B42EB73976A26A2
AD4C75D9809D5BF272DC66CCA2024826
6A71C6170565C0D9EAA82F2EB1DB5F13
D1FAB7F3F72EAE65EEA470EBCF429EC2
DD9337BC93D3879106BB495CBA49B2C8
EB60AA3561668493D69C4A7BC32A7792
FD4A0166E53F41B6F6A876BEF77795C9
8771D4E17B9A401A6A2D3E7555A5B6A9
E4DEF4FF50E3AE62A33B3DA165C2F653
C85E8606EFF5B1D4919647DC9FD6872C
0E68B6E858E7FF636AE621782A158CF7
1EA1F2A8E4041A597BAA78D858A656B3
1FFE840CA070794A89F31E1690E8779E

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 08, 2010 May 08, 2010

Scratch that. I forgot CF's hash(..) does not accept binary.

Message was edited by: -==cfSearching==-

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 08, 2010 May 08, 2010

Ah, ok.  Yeah, I got:

ByteArray objects cannot be converted to strings.

The error occurred in /web/joomla/abbott/md5files.cfm: line 15

13 : #dmfilename# --

14 : <cffile file="/web/joomla/dmdocuments/#dmfilename#" variable="xFile" action="readbinary">

15 : #hash(xFile,"MD5")# <br />

So, any hope?

--ja

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 08, 2010 May 08, 2010

I figured it out!  Here is the solution:

<cfset joomlaPROD = "motherJoomla">

<cfquery name="data2"

datasource="#joomlaPROD#">

    select jos_docman.id, `dmname`,

dmdescription, dmfilename

    from jos_docman 

    limit

100

</cfquery>

053f35a9c39ec156c9f1fd8a56fc0d8a

/web/joomla/dmdocuments/w-sw7-13.pdf<br />

<br />

<cfparam

name="checkSumHex" default="">

<cfoutput query="data2">

#dmfilename# --

<cffile file="/web/joomla/dmdocuments/#dmfilename#" variable="xFile"

action="readbinary">

<cfset md5 = createObject("java","java.security.MessageDigest").getInstance("MD5")>

<cfset md5.update(xFile,0,len(xFile))>

<cfset checksumByteArray = md5.digest()>

<cfloop from="1" to="#len(checksumByteArray)#" index="i">

<cfset hexCouplet = formatBaseN(bitAND(checksumByteArray,255),16)>

<!--- Pad with 0's --->

   <cfif len(hexCouplet) EQ 1>

      <cfset

hexCouplet = "0#hexCouplet#">

   </cfif>

   <cfset checkSumHex =

"#checkSumHex##hexCouplet#">

</cfloop>

Binary Hash: #checkSumHex#<br/>

<cfset checkSumHex = "">

</cfoutput>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2010 May 09, 2010

Do you wanna mark the issue as "answered".

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 09, 2010 May 09, 2010
LATEST

Solved.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 09, 2010 May 09, 2010

That is odd you get different results.  A gnuwin32 port of md5sum gives me the same results as #hash( cffileRead )# and apache DigestUtils - and your code.

<cfset path = "c:\someTestFile.zip">
<cffile action="read" file="#path#" variable="out">
<cfoutput>#hash(out)#</cfoutput><br>

http://commons.apache.org/codec/apidocs/org/apache/commons/codec/digest/DigestUtils.html#md5Hex%28byte[]%29

<cfset util = createObject("java",  "org.apache.commons.codec.digest.DigestUtils")>
<cfset bin = FileReadBinary(path)>
<cfoutput>#util.md5Hex(bin)#</cfoutput><br>

But I am glad you found something that works.

Message was edited by: -==cfSearching==-

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources