jwt加密
string token = new JwtBuilder()
.WithAlgorithm(new HMACSHA256Algorithm()) // 使用算法
.WithSecret(HearingRehabilitation.BusinessLayer.Cfg.Secret) // 使用秘钥
.AddClaim("exp", DateTimeOffset.UtcNow.AddMonths(1).ToUnixTimeSeconds())
.AddClaim("claim2", "claim2-value")
.Build();
try
{
string json = new JwtBuilder()
.WithSecret(HearingRehabilitation.BusinessLayer.Cfg.Secret)
.MustVerifySignature()
.Decode(token);
Console.WriteLine(json);
}
catch (TokenExpiredException)
{
Console.WriteLine("token 已过期");
}
catch (SignatureVerificationException)
{
Console.WriteLine("token 签名无效");
}
return true;