Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript中的Amazon S3授权头(java到javascript)_Javascript_Java_Node.js_Amazon S3_Cryptography - Fatal编程技术网

javascript中的Amazon S3授权头(java到javascript)

javascript中的Amazon S3授权头(java到javascript),javascript,java,node.js,amazon-s3,cryptography,Javascript,Java,Node.js,Amazon S3,Cryptography,我正在尝试用javascript重建AmazonS3授权头。目前我拥有的是这个 const encoder = new TextEncoder('utf-8'); stringToSign = encoder.encode(stringToSign); let decode = Buffer.from(secretKey, 'base64'); decode = encoder.encode(decode); var hmac = crypto.createHmac('sha1', decode

我正在尝试用javascript重建AmazonS3授权头。目前我拥有的是这个

const encoder = new TextEncoder('utf-8');
stringToSign = encoder.encode(stringToSign);
let decode = Buffer.from(secretKey, 'base64');
decode = encoder.encode(decode);
var hmac = crypto.createHmac('sha1', decode).update(new Buffer(base64Policy, 'utf-8')).digest('base64');
stringToSign

POST 
594bc6507c5ea009b944afcbed445d8c 
application/x-www-form-urlencoded; charset=utf-8 
Sun, 25 Apr 2021 20:48:06 GMT 
N2Y3Y2MwYjY4MjM4NGJlNzg2Y2I2NmUxMWE4NjRjMzY=
secretKey

POST 
594bc6507c5ea009b944afcbed445d8c 
application/x-www-form-urlencoded; charset=utf-8 
Sun, 25 Apr 2021 20:48:06 GMT 
N2Y3Y2MwYjY4MjM4NGJlNzg2Y2I2NmUxMWE4NjRjMzY=
不用担心这些密钥的保密性,它们在我的本地环境中

HMAC的结果是
3EAV8OAJ14NR22W6Z3RTBSMTD4=
根据长度判断其正确,但由于某种原因其格式不正确

我有我们的旧java应用程序的源代码,类似这样

String str7 = method + "\n" + md5Hash + "\n" + "application/x-www-form-urlencoded; charset=utf-8" + "\n" + date + "\n" + "\n" + urlSegment;
Mac instance = Mac.getInstance("HmacSHA1");
byte[] decode = Base64.decode(str4, 0);
instance.init(new SecretKeySpec(decode, instance.getAlgorithm()));
Charset charset = Charsets.UTF_8;
if (str7 != null) {
    byte[] bytes = str7.getBytes(charset);
    byte[] encode = Base64.encode(instance.doFinal(bytes), 0);
    String str8 = "PWS " + keyId + ':' + new String(encode, Charsets.UTF_8);

    if (str8 != null) {
        return StringsKt.trim((CharSequence) str8).toString();
    }
}
有人能告诉我我做错了什么吗?我也咨询过

但我觉得有点不同