12 lines
398 B
JavaScript
12 lines
398 B
JavaScript
import CryptoJS from 'crypto-js'
|
|
|
|
// HMAC-SHA256加密
|
|
export function hmacSHA256(message, secret) {
|
|
return CryptoJS.HmacSHA256(message, secret).toString(CryptoJS.enc.Hex)
|
|
}
|
|
|
|
// 生成请求签名
|
|
export function generateRequestSignature(userId, timestamp, method, url, secret) {
|
|
const signString = userId + timestamp + method.toUpperCase() + url
|
|
return hmacSHA256(signString, secret)
|
|
} |