gpt4 book ai didi

javascript - 使用 Javascript 签署 key HMAC SHA1

转载 作者:行者123 更新时间:2023-12-04 18:03:53 27 4
gpt4 key购买 nike

出于某种原因,我无法从 JS 中的私钥创建签名。使用来自谷歌的在线帮助:

https://m4b-url-signer.appspot.com/

网址:https://google.maps.com/maps/api/geocode/json?address=New+York&client=test

示例 key (为了练习目的而伪造的) key :QNade5DtdJKKZbidTsrIgONupc4=

(结果)签名:XDsiH5JAY7kJLgA1K2PWlhTdO1k=

但是,我的 javascript 代码:

var keyString = 'QNade5DtdJKKZbidTsrIgONupc4=';
console.log(keyString)

var urlString = encodeURIComponent('/maps/api/geocode/json?address=New+York&client=test');
console.log(urlString)

// We need to decode private key to binary
var decoded_key_words = CryptoJS.enc.Utf8.parse(keyString);
var decoded_key = CryptoJS.enc.Base64.stringify(decoded_key_words);

console.log(decoded_key);

var signature = CryptoJS.HmacSHA1(decoded_key,urlString);
console.log(signature);

// Encode binary signature to base 64
var encoded_signature = CryptoJS.enc.Base64.stringify(signature);
console.log(encoded_signature)

给我一​​个签名:

bOenVNeXI6xI1xlSa77oqGKssyY=

我似乎无法弄清楚我做错了什么。我是否错误地解码了 base64?

最佳答案

郑重声明,这有效:

<script src="sha.js"></script>

var url = '/maps/api/geocode/json?address=New+York&client=test';
var key = 'QNade5DtdJKKZbidTsrIgONupc4='

var hmacObj = new jsSHA(url, 'TEXT');
var hmacOutput = hmacObj.getHMAC(key,'B64','SHA-1','B64');

console.log(hmacOutput)

给我:

XDsiH5JAY7kJLgA1K2PWlhTdO1k=

关于javascript - 使用 Javascript 签署 key HMAC SHA1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30379084/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com