public static string GenerateToken(string Username)
{
var claimsdata = new[] { new Claim(ClaimTypes.Name, Username) };
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("qwertyuioplkjhgfdsazxcvbnmqwertlkjfdslkjflksjfklsjfklsjdflskjflyuioplkjhgfdsazxcvbnmmnbv"));
var signInCred = new SigningCredentials(key, SecurityAlgorithms.HmacSha384Signature);
var token = new JwtSecurityToken(
issuer: "mysite",
audience: "mysite",
expires: DateTime.Now.AddMinutes(60),
claims: claimsdata,
signingCredentials: signInCred
);
var tokenString = new JwtSecurityTokenHandler().WriteToken(token);
return tokenString;
}
//密钥的长度为88个字符。如果我将其减少到少于16个字符,则会出现异常:
System.ArgumentOutOfRangeException:'IDX10603:解密失败。 尝试过的键:“ [PII隐藏]”。捕获到异常:“ [PII隐藏]”。 令牌:“ [PII隐藏]”