Re请问Node.js后端签名直传,上传回调到服务器之后怎么验证oss签名
上传文件成功,nodejs验证回调签名不成功,请问大佬们怎么处理?
-------------------------
Re请问Node.js后端签名直传,上传回调到服务器之后怎么验证oss签名
function
test(
oss_callback) {
const signature
=
Buffer.
from(oss_callback.authorization,
'
base64
').
toString();//callback签名
const x_oss_pub_key_url
= oss_callback[
'
x-oss-pub-key-url
'];
const pub_key_url
=
Buffer.
from(x_oss_pub_key_url,
'
base64
').
toString();
if (pub_key_url.
match(
/
http
[
s
]
?
\:\/\/gosspublic\.alicdn\.com\/
/)) {
request(pub_key_url,
function (
error,
response,
public_key) {
console.
log(public_key);
//公钥
const sign_str
=
md5(
decodeURI(path)
+
'
\n
'
+ querystring.
stringify(reqbody)); //签名字符串
var verifier
= crypto.
createVerify(
'
md5WithRSAEncryption
');
verifier.
update(
Buffer.
from(sign_str));
console.
log(verifier.
verify(public_key, signature,
'
base64
'));
});
}
else {
throw
new
Error(
'
public key url illegal
')
}
}