As the title, jwtSecurityTokenHandler.WriteToken(jwt) function is throwing IDX10653 Error. Full exception down there.
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
And my example usage is down there:
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
};
}
I controlled my every variable and function. I think There is not a wrong thing and I don't find any solution for this error code. Any solution?
Edit: In the inner details an extra infos ->
Key 'Microsoft.IdentityModel.Tokens.SymmetricSecurityKey', is of size: 'System.Int32'. (Parameter 'key')
My SecurityKey creator function is like:
public static SecurityKey CreateSecurityKey(string securityKey)
{
return new SymmetricSecurityKey(Encoding.UTF8.GetBytes(securityKey));
}
That problem is solved.
The password ("SecurityKey") in the TokenOptions section in the appsettings.json file in the WebApi layer was short when working with the SHA512 encryption system and varbinary(500).
"TokenOptions": {
"Audience": "[email protected]",
"Issuer": "[email protected]",
"AccessTokenExpiration": 10,
"SecurityKey": "mykey"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With