IDX10653: The encryption algorithm 'HS256' requires a key size of at least '128' bits. Key 'Null', is of size: '112'. is thrown when you sign a token with a symmetric key that is too short. The key string here was 14 characters, and the message reports 112 bits. Use a longer key (the one that worked in the test is 44 characters) and the token is created.

The exception comes from the code that creates the token, not from the API that validates it: the token is never written, so there is nothing to send. Make the key longer in the configuration both sides read.

The error

cmd /c ".\mint\bin\Debug\net10.0\Mint.exe short-test-key https://issuer.test fix11-api 30 0 2>&1"
Unhandled exception. System.ArgumentOutOfRangeException: IDX10653: The encryption algorithm 'HS256' requires a key size of at least '128' bits. Key 'Null', is of size: '112'. (Parameter 'key')
   at Microsoft.IdentityModel.Tokens.SymmetricSignatureProvider..ctor(SecurityKey key, String algorithm, Boolean willCreateSignatures)
...
   at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.WriteToken(SecurityToken token)
...

This is the console project's standard error, merged into the output by cmd /c ... 2>&1 so that PowerShell printed it as plain lines. In an earlier run the process exited with code -532462766, and run directly in PowerShell the same text appeared wrapped inside a NativeCommandError record.

Why it happens

HMAC-SHA256 signing in Microsoft.IdentityModel refuses keys under the size it prints, here 128 bits. The test's code turns the string into a key with Encoding.UTF8.GetBytes; short-test-key is 14 characters, and the message says 112 bits. Only ASCII keys were tested. The stack trace shows the exception raised under WriteToken, while the signature provider is created. The test's key has no key id, and the message prints Key 'Null'.

Note that the message on this version (System.IdentityModel.Tokens.Jwt 8.19.2) says 128 bits for HS256. The test did not try the other HMAC algorithms.

The fix

The token maker's code, unchanged, from the test's Program.cs:

var credentials = new SigningCredentials(
    new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)),
    SecurityAlgorithms.HmacSha256);

Called with the API's 44-character test key instead:

.\mint\bin\Debug\net10.0\Mint.exe "fix11-test-only-signing-key-0123456789abcdef" https://issuer.test fix11-api 30 0 *> "$d\logs\shortkey-fix.txt"; "exit=$LASTEXITCODE"
exit=0

The file then held a token, and tokens made with this key got a 200 from the test API. Generate a long random key once, keep it out of source control (user-secrets in development, an environment variable or a secret store in production), and read it from the same configuration key in the code that signs and the code that validates.

How it was reproduced

A dotnet new console -f net10.0 project with System.IdentityModel.Tokens.Jwt 8.19.2, which builds a JwtSecurityToken with HS256 signing credentials from a key passed on the command line and writes it with JwtSecurityTokenHandler; SDK 11.0.100, .NET 10 runtime, Windows PowerShell 5.1. Both keys are made-up test strings. The API that validates these tokens used Microsoft.AspNetCore.Authentication.JwtBearer 10.0.15 and was not involved in this error.

Frequently asked

How long must a JWT HS256 key be in .NET?
On System.IdentityModel.Tokens.Jwt 8.19.2 the message says at least 128 bits. A 14-character key failed with IDX10653 and a 44-character key worked.
Why does IDX10653 say Key 'Null'?
The test's SymmetricSecurityKey had no key id, and the message printed Key 'Null'. The key string was 14 ASCII characters and the size reported was 112 bits.
Where is IDX10653 thrown, in the API or in the token code?
In the code that creates the token: the exception came from JwtSecurityTokenHandler.WriteToken in the console project, before any request reached the API.

More decoded errors in the Fixes category. A token signed with a different key than the API's fails later, at validation: The signature key was not found (IDX10517).