From: Dan M. <dan...@gm...> - 2012-11-03 17:19:45
|
Claudius has figured out that his EXPath crypto:hash() function does in fact do the correct hash on the binary of the base64binary (not the string version of the base64binary) to match the value that we get from a file system or from the HEAD of S3 for a binary file. So by just changing over to use his hash function we can now correctly verify the md5 checksums of a file on disk. Everyone should note that the util:hash() and the crypto:hash() work the same for string but not the same on base64Binary types. I think this might be considered a bug and I will add it to the bug tracker if other people agree. Thanks Claudius! By the way you can get the latest 0.2.2 version of the EXPATH crypto module here: http://code.google.com/p/existdb-contrib/downloads/list And then just use the "Upload" on the package installer. On the trunk you will need to change the conf.xml from: <module uri="http://kuberam.ro/ns/x-crypt" class="ro.kuberam.xcrypt.XcryptModule" /> to be <module uri="http://expath.org/ns/crypto" class="org.expath.exist.crypto.ExistExpathCryptoModule" /> Note that we could not get the module to work when the jar file was in the new package location here /webapp/WEB-INF/expathrepo/expath-crypto-0.2.2/expath-crypto So Claudius suggested that we manually copy the jar file into lib/extensions and that worked. Thanks! - Dan On Sat, Nov 3, 2012 at 9:19 AM, Dan McCreary <dan...@gm...> wrote: > I think the thing that Nick is trying to do is calculate the hash of > the binary file on disk, not the base64Binary of the binary file. > > Here is a test I ran to show what we can do. > > xquery version "1.0"; > > (: this is the value we get when we do the following: > on the mac > $ echo -n 'Hello World!' | md5 > > on windows with cygwin > $ echo -n 'Hello World!' | md5sum > ed076287532e86365e841e92bfc50d8c *- > > $ md5sum red-square.png > 28ec5059f163077a7734212d899a2175 *red-square.png > > Here we must take a binary file and get the base64 of it without any spaces > $ base64 -w0 red-square.png | md5sum > a339d67a458e9e7c707a7251e9a95bec *- > > :) > let $expected-value-hash-string := 'ed076287532e86365e841e92bfc50d8c' > > let $hash-hello-world := util:hash('Hello World!', 'md5', false()) > > let $md5-string-test := > if ($hash-hello-world = $expected-value-hash-string) > then 'pass' > else 'fail' > > (: test on a small binary png file in /tmp > > $ md5sum red-square.png > 28ec5059f163077a7734212d899a2175 *red-square.png > > Here we must take a binary file and get the base64 of it without any spaces > $ base64 -w0 red-square.png | md5sum > a339d67a458e9e7c707a7251e9a95bec *- > > :) > let $image-as-base-64 := util:binary-doc('/tmp/red-square.png') > > let $hash-red-square := util:hash($image-as-base-64, 'md5', false()) > > let $hash-of-base64Binary-of-image := 'a339d67a458e9e7c707a7251e9a95bec' > > let $md5-base64-of-binary-test := > if ( $hash-red-square =$hash-of-base64Binary-of-image) > then 'pass' > else 'fail' > > return > <testcase name="md5-hash-on-binaries" classname="md5-binary"> > <hash-hello-world>{$hash-hello-world}</hash-hello-world> > <string-pass-fail-code>{$md5-string-test}</string-pass-fail-code> > > <hash-png>{$hash-red-square}</hash-png> > <binary-pass-fail-code>{$md5-base64-of-binary-test}</binary-pass-fail-code> > </testcase> > > > which returns: > > <testcase name="md5-hash-on-binaries" classname="md5-binary"> > <hash-hello-world>ed076287532e86365e841e92bfc50d8c</hash-hello-world> > <string-pass-fail-code>pass</string-pass-fail-code> > <hash-png>a339d67a458e9e7c707a7251e9a95bec</hash-png> > <binary-pass-fail-code>pass</binary-pass-fail-code> > </testcase> > > But is there a way to get the hash of a true binary within XQuery? > > - Dan > > On Sat, Nov 3, 2012 at 8:45 AM, nsincaglia <nsi...@nu...> wrote: >> I am using Release 2.0. >> >> >> >> -- >> View this message in context: http://exist.2174344.n4.nabble.com/md5-hash-sum-of-base64-binary-tp4657005p4657007.html >> Sent from the exist-open mailing list archive at Nabble.com. >> >> ------------------------------------------------------------------------------ >> LogMeIn Central: Instant, anywhere, Remote PC access and management. >> Stay in control, update software, and manage PCs from one command center >> Diagnose problems and improve visibility into emerging IT issues >> Automate, monitor and manage. Do more in less time with Central >> http://p.sf.net/sfu/logmein12331_d2d >> _______________________________________________ >> Exist-open mailing list >> Exi...@li... >> https://lists.sourceforge.net/lists/listinfo/exist-open > > > > -- > Dan McCreary > NoSQL Evangelist > office: (952) 931-9198 > cell: (612) 986-1552 -- Dan McCreary NoSQL Evangelist office: (952) 931-9198 cell: (612) 986-1552 |