CodeDocu.com

Error: System.ArgumentOutOfRangeException The algorithm: 'HS256' requires the SecurityKey.KeySize to be greater than '128' bits

 

The error message occurs when creating a security token for authentication

 

Asp.Net Core Wep Api, Identity, Authentication, JWTBearer

 

Error message in the code

System.ArgumentOutOfRangeException

  HResult=0x80131502

  Message=IDX10603:

The algorithm: 'HS256' requires the SecurityKey.KeySize to be greater than '128' bits.

KeySize reported: '80'.

Source=Microsoft.IdentityModel.Tokens

 

Error The algorithm HS256 requires the SecurityKey.KeySize to be greater than 128 bits

 

The error occurs when one

SymmetricSecurityKey securityKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secret));

            return securityKey;

 

using Microsoft.IdentityModel.Tokens;   //*Token

 

Solution:

You have to enter a longer coding key

In this case, the secret_Encoder_Key was changed from "123456789" to "1234567890 a very long word"

 

C # code

//< ok output JwtToken >

            String secret_Encoder_Key = "1234567890 a very long word";

            JwtToken  token = new JwtTokenBuilder()

                .AddSecurityKey(JwtSecurityKey.Create(secret_Encoder_Key))

                .AddSubject("Api-Test")

                .AddIssuer("Test.Security.Bearer")

                .AddAudience("Test.Security.Bearer")

                //.AddClaim("EmployeeNumber", "1234")

                .AddExpiry(5) //Lifetime in Minutes

                .Build();

 

            //return Ok(token);

 

 

 

 

Error The algorithm HS256 requires the SecurityKey.KeySize to be greater than 128 bits

  Stack trace:

   at Microsoft.IdentityModel.Tokens.SymmetricSignatureProvider ..ctor (SecurityKey key, String algorithm)

   at Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateSignatureProvider (SecurityKey key, String algorithm, Boolean willCreateSignatures)

   at Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateForSigning (SecurityKey key, String algorithm)

   at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateEncodedSignature (String input, SigningCredentials signingCredentials)

   at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.WriteToken (SecurityToken token)

   at Freelancer.Provider.JWT.JwtToken.get_JwtToken_String () in C: \ _ Data \ Desktop \ VS_Projects \ Web \ Freelancer \ Freelancer \ Provider \ JWT \ JwtToken.cs: line 25

   at Freelancer.Controllers.TokenController.Create (LoginInputModel inputModel) in C: \ _ Data \ Desktop \ VS_Projects \ Web \ Freelancer \ Freelancer \ Controllers \ TokenController.cs: line 54

   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute (Object target, Object [] parameters)

   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker. <InvokeActionMethodAsync> d__12.MoveNext ()


Software Entwicklung Stuttgart NĂ¼rtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel