简体   繁体   中英

Dojo MD5 hash not in base 16 notation

I would like to generate an MD5 hash in Dojo that will match my hash in Java, using MessageDigest . I'm looking to generate a base 16 md5 hash in Dojo. How do you do this?

dojo.require("dojox.encoding.digests.MD5");
var d = dojox.encoding.digests.MD5("test");

//gives me CY9rzUYh03PK3k6DJie09g== 

//was hoping for 098f6bcd4621d373cade4e832627b4f6 

I'm not finding much documentation online about this.

The dojo MD5 method has a second parameter that accepts an outputType :

d = dojox.encoding.digests.MD5("test", dojox.encoding.digests.outputTypes.Hex);

The API docs are confusing. You don't pass in an object, just the output type, which is just a constant integer.

Demo: JSFiddle .

References: API , Guide

that's Base64 encoding. If you are willing to do the decoding on the Java side (to compare with the MessageDigest output), then you can use the decodeBase64 method from Apache Commons codec to get a byte array, then compare the byte array output from MessageDigest

if you want to compare on the javascript side, I would instead use encodeBase64String to encode the byte array coming out of MessageDigest, and compare the base64 strings on the JS side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM