I am new to HMAC-SHA1 signature creation using javascript. I found this code, in that i don't know, parameter 'secret' value.
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/hmac-sha256.js"> </script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/enc-base64-min.js"></script>
<script>
var hash = CryptoJS.HmacSHA256("Message", "secret");
var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
document.write(hashInBase64);
</script>
The secret
is just the key you use to create the signed hash, it's up to you to decide it.
Keep in mind that, since it is client side code, anyone looking the page source can see it!
we can use Crypto for creating the HmacSHA1 signature using our consumer secret code and body data with the current date see the code below.
//import the crypto js in your machine..... import cryptoJs from "crypto-js";
#secret (consumer secret key) #message (body data with current date) const signature = cryptoJs.HmacSHA1(JSON.stringify(message), secret).toString();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.