chalos / crypto-js

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

Allow hexadecimal input type into the hashing functions #113

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
There's a number of scenarios where I need to be able to input hexadecimal 
input into the hash algorithm and receive a hexadecimal output, however it 
currently only accepts input as text.

Potential scenarios:
1) HMAC(key, msg) with the key or msg being in hex or base64.
2) Hash(key, nonce || message) the nonce or key is likely random bits so 
everything would need to be in the same input format.

Are you able to enable hex as an input option? There is another library which 
allows similar hex and base64 inputs to the hash (jsSHA) but this library only 
supports the SHA algorithms. I would prefer Keccak over NSA designed SHA512.

http://caligatio.github.io/jsSHA/

Original issue reported on code.google.com by john.f.m...@gmail.com on 28 Jan 2014 at 5:11

GoogleCodeExporter commented 8 years ago
I found out it is indeed possible to have hex input. First you must convert the 
input to hex using the helper functions. E.g.

// CryptoJS.HmacSHA512("Message", "Secret Passphrase");
var wordsKey = CryptoJS.enc.Hex.parse('001122334455');
var wordsMsg = CryptoJS.enc.Hex.parse('aabbccddeeff');
var hash = CryptoJS.HmacSHA512(wordsMsg, wordsKey);
var output = hash.toString(CryptoJS.enc.Hex);

See here:
https://stackoverflow.com/questions/22183337/are-there-any-javascript-cryptograp
hic-hmac-libraries-that-accepts-hex-input

This issue can now be closed. Thankyou!

Original comment by john.f.m...@gmail.com on 10 Mar 2014 at 2:56