阿里云 cdn 签名
阿里 CDN 方式1
计算方式
ts
import CryptoJS from "crypto-js";
const generateHash = (url, key) => {
// Generate 10-digit timestamp
const ts = Math.floor(Date.now() / 1000).toString();
// Generate UUID and remove hyphens
const uid = crypto.randomUUID().replace(/-/g, "");
// Create input string
const input = `${url}-${ts}-${uid}-0-${key}`;
// Calculate MD5 hash
const hashResult = CryptoJS.MD5(input);
const hashValue = hashResult.toString(CryptoJS.enc.Hex);
// Generate auth_key string
const authKeyValue = `auth_key=${ts}-${uid}-0-${hashValue}`;
return { hash: hashValue, timestamp: ts, uuid: uid, authKey: authKeyValue };
};uid 是 随机数,并不一定非要是 uuid ,使用 0 也是可以的。