这就是我现在为生成 JWT 令牌所做的工作。如何在不使用任何其他 npde 包的情况下仅使用加密库生成 JWE 令牌?
var Header = {"alg": "HS256","typ": "JWT"},
Payload = {"content": "valuable data"},
secret_key = "xxxxx123xxxxxxxx123xxxxxxxx";
function create_jwt(Header, Payload) {
var encodedString = btoa(JSON.stringify(Header)) + "." + btoa(JSON.stringify(Payload));
var hmac_hash = z.hmac('sha256', secret_key, encodedString, "base64");
return console.log(encodedString + "." + hmac_hash);
}