New to JS, I\'m also learning to use crypto libraries. I don\'t understand why signing/encoding the same message with the same secret yields differing results.
I\'m
There are 3 errors in your code :)
You're missing the enc-base64-min.js
for crypto-js
. Without it, CryptoJS.enc.Base64
will be undefined
You're missing a parameter when calling .getHMAC()
. It's .getHMAC(secret, secret_type, hash_type, output_encoding)
With 1+2 adding a =
isn't necessary (nor right)
<script src="lib/jsSHA/src/sha1.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/hmac-sha1.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/enc-base64-min.js"></script>
var message = "shah me";
var secret = "hide me";
var crypto = CryptoJS.HmacSHA1(message, secret).toString(CryptoJS.enc.Base64);
var shaObj = new jsSHA(message, "ASCII");
var jssha = shaObj.getHMAC(secret, "ASCII", "SHA-1", "B64");
return "crypto answer is " + crypto + " jssha answer is " + jssha;
Example