SK-Yang / crypto-js

Automatically exported from code.google.com/p/crypto-js
0 stars 0 forks source link

Support binary input types #67

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by e...@dnanexus.com on 22 Jan 2013 at 8:50

GoogleCodeExporter commented 9 years ago
I 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) );

Original comment by Jeff.Mott.OR on 22 Jan 2013 at 8:54

GoogleCodeExporter commented 9 years ago
Thanks for the quick reply Jeff. Also that WordArray workaround will be 
perfect! Is there also a workaround for Blob?

Thanks,
Evan

Original comment by e...@dnanexus.com on 22 Jan 2013 at 9:17

GoogleCodeExporter commented 9 years ago
Actually, 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!

Original comment by e...@dnanexus.com on 22 Jan 2013 at 10:24

Attachments:

GoogleCodeExporter commented 9 years ago
Ahh. 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.

Original comment by Jeff.Mott.OR on 22 Jan 2013 at 11:24

GoogleCodeExporter commented 9 years ago
Ah, pefect! Thank you!

Original comment by e...@dnanexus.com on 22 Jan 2013 at 11:36

GoogleCodeExporter commented 9 years ago
Is 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

Original comment by wolfgang...@gmail.com on 23 Jan 2013 at 5:38

GoogleCodeExporter commented 9 years ago
Ah, I used readAsArrayBuffer instead and this method seems to be working now.

Is it difficult to handle "BinaryString"s ?

Original comment by wolfgang...@gmail.com on 23 Jan 2013 at 5:48

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Wolfgang, I'd suggest you stick with readAsArrayBuffer. 
FileReader.readAsBinaryString has been deprecated - 
https://developer.mozilla.org/en-US/docs/DOM/FileReaderSync#readAsBinaryString()
_Deprecated.

Original comment by e...@dnanexus.com on 23 Jan 2013 at 5:50

GoogleCodeExporter commented 9 years ago
Yeah, 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 :-)

Original comment by wolfgang...@gmail.com on 23 Jan 2013 at 5:53

GoogleCodeExporter commented 9 years ago
Indeed 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

Original comment by e...@dnanexus.com on 23 Jan 2013 at 5:57

GoogleCodeExporter commented 9 years ago
Very 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).

Original comment by wolfgang...@gmail.com on 23 Jan 2013 at 6:10

GoogleCodeExporter commented 9 years ago
Just 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

Original comment by xcam...@gmail.com on 10 Oct 2013 at 10:10

GoogleCodeExporter commented 9 years ago
Converting 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?

Original comment by shach...@gmail.com on 18 Jun 2014 at 11:25