简体   繁体   English

使用 javascript 创建 HAMC-SHA1 签名

[英]HAMC-SHA1 signature creation using javascript

I am new to HMAC-SHA1 signature creation using javascript. I found this code, in that i don't know, parameter 'secret' value.我是使用 javascript 创建 HMAC-SHA1 签名的新手。我发现这段代码,我不知道,参数“秘密”值。

 <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. secret只是创建签名哈希所使用的密钥,由您决定。

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.我们可以使用 Crypto 创建 HmacSHA1 签名,使用我们的消费者密码和当前日期的正文数据,请参见下面的代码。

//import the crypto js in your machine..... import cryptoJs from "crypto-js"; //在您的机器中导入加密 js..... 从“crypto-js”导入 cryptoJs;

#secret (consumer secret key) #message (body data with current date) const signature = cryptoJs.HmacSHA1(JSON.stringify(message), secret).toString(); #secret(消费者密钥)#message(当前日期的正文数据)const signature = cryptoJs.HmacSHA1(JSON.stringify(message), secret).toString();

source code源代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM