Closed wingsergey closed 9 years ago
The second argument when set to true
returns the raw (bytes) result. Remove it or set it to false
to get a hex
result.
Oh nvm, I have read the md5 documentation now and I understand your issue.
What you can advise to me? Can you implement such feature?
Yes I could implement such feature. Actually the correct way is to return a binary string instead of what is being returned now. I need some time to actually implement this because I'm currently very busy at work.
For now the fastest way for you is to do something like this:
function hex2bin(hex) {
var bytes = [];
for (var i = 0; i < hex.length - 1; i += 2) {
bytes.push(parseInt(hex.substr(i, 2), 16));
}
return String.fromCharCode.apply(String, bytes);
}
hex2bin(SparkMD5.hashBinary(yourstuff)); // This returns a binary string of 16 chars
It helped. Thank you very much. You are genius.
Hehe, thanks for the compliment.
Version 2.0.0
now returns a binary string if raw
is true, similar to other languages such as PHP. See: https://github.com/satazor/SparkMD5/commit/80acecd301a70f75f7ac76c3883442be05c33d8e
I tried to use your awesome library to get raw result but got array with '1746531795,941883451,402336312,-1378573203'.
I expected for string 16 chars length. What I do wrong?
You can reproduce it on you examples from test directory. Just set second parameter to
true
as in instructionSparkMD5.hashBinary(e.target.result, true)
.How I can get raw binary string like in php function md5(str, true); ?