What steps will reproduce the problem? 1. Use the javascript ArrayBuffer interface as the input to computing an md5checksum.
What is the expected output? What do you see instead? I'd expect that the "update" interface can take either a string or typed arrays. Instead I get an error because the Uint32Array doesn't behave as a String.
What version of the product are you using? On what operating system? 3.1, Ubuntu.
Please provide any additional information below.
Comment #1
Posted on Jan 22, 2013 by Happy HorseI think it's reasonable to expect update() to accept typed arrays. I'll likely change that. In the mean time, you'll have to do this:
md5.update( CryptoJS.lib.WordArray.create(typedArray) );
Comment #2
Posted on Jan 22, 2013 by Quick KangarooThanks for the quick reply Jeff. Also that WordArray workaround will be perfect! Is there also a workaround for Blob?
Thanks, Evan
Comment #3
Posted on Jan 22, 2013 by Quick KangarooActually, I don't think this works. Please see the attached file for an example using an ArrayBuffer. Can we change the issue type to bug? Is there any other way I can accomplish this? I'm desperately in need of a way to incrementally compute the MD5 checksum of a binary file in javascript. Thanks for your help!
- crytpo-js-binary-data-bug.tar.gz 268.44KB
Comment #4
Posted on Jan 22, 2013 by Happy HorseAhh. I didn't document this very well... or, at all, for that matter... but typed array support comes in a separate component. So include...
<script src='md5-3.1.2.min.js'></script>
<script src='http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/lib-typedarrays-min.js'></script>
...then everything should just work.
Comment #5
Posted on Jan 22, 2013 by Quick KangarooAh, pefect! Thank you!
Comment #6
Posted on Jan 23, 2013 by Massive PandaIs this also working with SHA1? I am trying to compute the SHA1 hash of an entire MP3 file in the browser, and I am getting hashes that do not match what I expect even after trying: CryptoJS.lib.WordArray.create
This file is loaded via a FileReader calling readAsBinaryString
Comment #7
Posted on Jan 23, 2013 by Massive PandaAh, I used readAsArrayBuffer instead and this method seems to be working now.
Is it difficult to handle "BinaryString"s ?
Comment #8
Posted on Jan 23, 2013 by Quick KangarooComment deleted
Comment #9
Posted on Jan 23, 2013 by Quick KangarooWolfgang, I'd suggest you stick with readAsArrayBuffer. FileReader.readAsBinaryString has been deprecated - https://developer.mozilla.org/en-US/docs/DOM/FileReaderSync#readAsBinaryString()_Deprecated.
Comment #10
Posted on Jan 23, 2013 by Massive PandaYeah, I liked the ArrayBuffer initially and realized it wasn't easily supported by crypto-js until I found this issue.
I guess it isn't deprecated for the FileReader itself? But I don't mind using ArrayBuffers :-)
Comment #11
Posted on Jan 23, 2013 by Quick KangarooIndeed Jeff saved me when he showed me how to use ArrayBuffer. Also I do think readAsBinaryString has been removed from the spec, see http://www.w3.org/TR/FileAPI/, you won't find any mention of it.
Best, Evan
Comment #12
Posted on Jan 23, 2013 by Massive PandaVery good point with a good canonical link :-) I'm new to Javascript and just playing around (mostly), but these APIs are a little insane (input from multiple parties, things deprecated all over).
Comment #13
Posted on Oct 10, 2013 by Massive CamelJust for the record, I recently found an pretty old post on the Google Group with a snippet for building an ArrayBuffer (UInt8Array) from a WordArray. Here's the link:
https://groups.google.com/d/msg/crypto-js/TOb92tcJlU0/Eq7VZ5tpi-QJ
IMO, that would be an awesome addition to CryptoJS to have a full ArrayBuffer <-> ArrayBuffer flow.
Best
Comment #14
Posted on Jun 18, 2014 by Swift KangarooConverting the typedArray to string/word array is nice to get things working, but it's really slow. Is it possible to implement the algorithms directly from the typedArray?
Status: New
Labels:
Type-Enhancement
Priority-Medium