验签
验签
MD5 验签
MD5 验签示例
function verifyMD5(response) {
const data = Object.keys(response)
.sort()
.reduce((obj, key) => {
obj[key] = response[key]
return obj
}, {})
var str = ''
Object.keys(data).forEach((key) => {
if (data[key] != '' && key != 'sign') {
str = str + key + '=' + data[key] + '&'
}
})
str = str + 'pkey=' + YOUR_MD5_SECRET_KEY
return md5(str) == response['sign']
}
RSA 验签签名
function verifyRSA(response) {
const data = Object.keys(response)
.sort()
.reduce((obj, key) => {
obj[key] = response[key]
return obj
}, {})
var str = ''
Object.keys(data).forEach((key) => {
if (data[key] != '' && key != 'sign') {
str = str + key + '=' + data[key] + '&'
}
})
var result = new NodeRSA(USEEPAY_RSA_PUBLICK_KEY, 'pkcs8-public').verify(
Buffer.from(str),
response['sign'],
'base64',
'base64',
)
return result
}
修改于 2023-01-31 06:06:00