Skip to content Skip to sidebar Skip to footer

Is Binary Hashing Possible With Cryptojs?

I want to create an HOTP client using javascript similar to SpeakEasy The above library is intended for server side javascript usage and it uses NodeJS. I want to do the same thing

Solution 1:

There is no such language that supports binary data strings in the code. You need to encode the binary data into some format such as Hex or Base64 and let CryptoJS decode it into it's own internal binary format which you then can pass to the various CryptoJS functions:

var wordArrayFromUtf = CryptoJS.enc.Utf8.parse("test");
var wordArrayFromHex = CryptoJS.enc.Hex.parse("74657374"); // "test"var wordArrayFromB64 = CryptoJS.enc.Base64.parse("dGVzdA=="); // "test"

Other functions are:

wordArrayFromHex.toString(CryptoJS.enc.Utf8)  // "test"
CryptoJS.enc.Utf8.stringify(wordArrayFromB64) // "test"

If you pass a string into a CrypoJS function (not these here), it will be assumed to be a Utf8-encoded string. If you don't want that, you need to decode it yourself.

Solution 2:

The code at http://caligatio.github.io/jsSHA/ works fine for SHA-512.

Drop the .js files, look in their test/test.html at line 515. It might look like a string to you but it is binary hex.

So their input is binary which is unmistaken. Don't get hung up on the fact it is sitting in a big string.

Post a Comment for "Is Binary Hashing Possible With Cryptojs?"