我在尝试使用 JWT 时遇到了 ıdx10653 错误- ASP.NETCORE 3.1

i'm gettin ıdx10653 error while i'm trying to use JWT- ASP.NETCORE 3.1

这是我尝试在 .net core 3.1 中使用 jwt 时的错误输出 我什么也得不到。

我正在使用 v3.1.10 版本的软件包,

我在 postman 上发布的数据正确插入到 database.But 我无法在 postman 响应行上获取令牌。

我的代码:

 public AccessToken CreateToken(User user, List<OperationClaim> operationClaims)
    {
        var securityKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey);
        var signingCredentials = SingingCredentialsHelper.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
        };


    }
public IDataResult<AccessToken> CreateAccessToken(User user)
    {
        var claims =_userService.GetClaims(user);
        var accessToken = _tokenHelper.CreateToken(user, claims);
        return new SuccessDataResult<AccessToken>(accessToken, Messages.AccessTokenCreated);

    }



    [HttpPost("register")]
    public ActionResult Register(UserForRegisterDto userForRegisterDto)
    {
        var userExists = _authService.UserExists(userForRegisterDto.Email);
        if (!userExists.Success)
        {
            return BadRequest(userExists.Message);
        }
        var registerResult = _authService.Register(userForRegisterDto, userForRegisterDto.Password);
        var result = _authService.CreateAccessToken(registerResult.Data);
        if (result.Success)
        {
            return Ok(result.Data);
        }
        return BadRequest(result.Message);
    }

我的错误输出是:

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'. '

There is a limitation of the SecretKey length used in the SymmetricSecurityKey before signing and generating the signed credentials.The key Secret key should be a minimum of 128 bits i.e (16 bytes).

所以你可以尝试让你的 SecurityKey 更长。