如标题, jwtSecurityTokenHandler.WriteToken(jwt) 函数抛出 IDX10653 错误。那里完全例外。
System.ArgumentOutOfRangeException: 'IDX10653:
The encryption algorithm 'System.String' requires a key size of at least 'System.Int32' bits.
Key 'Microsoft.IdentityModel.Tokens.SymmetricSecurityKey', is of size: 'System.Int32'. Arg_ParamName_Name
Run Code Online (Sandbox Code Playgroud)
我的示例用法如下:
public AccessToken CreateToken(User user, List<OperationClaim> operationClaims)
{
_accessTokenExpiration = DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration);
var securityKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey);
var signingCredentials = SigningCredentialsHelper.CreateSigningCredentials(securityKey);
var jwt = CreateJwtSecurityToken(_tokenOptions, user, signingCredentials, operationClaims);
var jwtSecurityTokenHandler = new JwtSecurityTokenHandler();
var token = jwtSecurityTokenHandler.WriteToken(jwt);
return new AccessToken
{
Token = token,
Expiration = _accessTokenExpiration
};
}
Run Code Online (Sandbox Code Playgroud)
我控制了我的每一个变量和函数。我认为没有错误,并且我没有找到该错误代码的任何解决方案。有什么解决办法吗?
编辑:在内部细节中额外的信息 - >
密钥“Microsoft.IdentityModel.Tokens.SymmetricSecurityKey”的大小为:“System.Int32”。(参数“键”) …