IDX10634: Unable to create the SignatureProvider. Algorithm: 'HS256', SecurityKey: 'Null' is not supported.
is thrown on the token-issuing side, by the .NET code that creates and signs the JWT, when the
key is of the wrong kind for the algorithm: here an RSA key with HS256, and in a second run a
symmetric key with RS256. In this test an RSA key with RS256 and the symmetric key with HS256
both wrote a token.
The exception comes from the code that signs the token; no request reaches an API. The
message prints the algorithm and, after SecurityKey:, the key's id: a rerun with
an RSA key given the id rsa1 printed SecurityKey: 'rsa1', and the keys
without an id printed 'Null'. Read the algorithm, then look at which key class
your code passes in. The key id rsa1, https://issuer.test,
fix11-api and the project name mint2 are the test's own.
The error
cmd /c ".\mint2\bin\Debug\net10.0\Mint.exe fix11-test-only-signing-key-0123456789abcdef https://issuer.test fix11-api 30 rsa 2>&1"
Unhandled exception. System.NotSupportedException: IDX10634: Unable to create the SignatureProvider.
Algorithm: 'HS256', SecurityKey: 'Null'
is not supported. The list of supported algorithms is available here: https://aka.ms/IdentityModel/supported-algorithms
...
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.WriteToken(SecurityToken token)
...
The console project's standard error, merged by cmd /c ... 2>&1; the
message itself breaks over three lines as shown. The rsa argument makes the
token maker sign with a new 2048-bit RSA key while the algorithm stays at its default, HS256.
The opposite mistake, the symmetric test key with alg=RS256, printed the same
message with the other algorithm:
cmd /c ".\mint2\bin\Debug\net10.0\Mint.exe fix11-test-only-signing-key-0123456789abcdef https://issuer.test fix11-api 30 alg=RS256 2>&1"
Unhandled exception. System.NotSupportedException: IDX10634: Unable to create the SignatureProvider.
Algorithm: 'RS256', SecurityKey: 'Null'
is not supported. The list of supported algorithms is available here: https://aka.ms/IdentityModel/supported-algorithms
...
The rerun with a key id on the RSA key:
cmd /c ".\mint2\bin\Debug\net10.0\Mint.exe fix11-test-only-signing-key-0123456789abcdef https://issuer.test fix11-api 30 rsa kid=rsa1 2>&1"
Unhandled exception. System.NotSupportedException: IDX10634: Unable to create the SignatureProvider.
Algorithm: 'HS256', SecurityKey: 'rsa1'
...
Why it happens
The SigningCredentials carry both the key and the algorithm name, and in the two
failing runs the pair did not fit: an RSA key with HS256, a symmetric key with RS256. The
stack trace shows the exception raised under WriteToken, where the signature is
created. The two pairs that worked are below.
The fix
The token maker's code, from the test's Program.cs:
...
SecurityKey signingKey = options.Contains("rsa")
? new RsaSecurityKey(RSA.Create(2048))
: new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
...
signingCredentials: new SigningCredentials(signingKey, alg));
...
The RSA key with RS256 wrote a token. It was the third command of one capture; the first two were the failing runs, whose exceptions went to standard error and were captured again as shown above. A short Python script of the test then decoded the token's header:
.\mint2\bin\Debug\net10.0\Mint.exe "fix11-test-only-signing-key-0123456789abcdef" https://issuer.test fix11-api 30 rsa alg=RS256
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
...
python .\decode_header.py .\logs2\c-rsa.txt
token header segment: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9
decoded: {"alg":"RS256","typ":"JWT"}
The symmetric key with HS256 wrote a token too:
.\mint2\bin\Debug\net10.0\Mint.exe "fix11-test-only-signing-key-0123456789abcdef" https://issuer.test fix11-api 30 alg=HS256
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
An API that validates the RS256 token would need the RSA public key as its
IssuerSigningKey; that side was not run here.
How it was reproduced
A console project (a copy of one made with dotnet new console -f net10.0) with
System.IdentityModel.Tokens.Jwt 8.19.2 that builds a JwtSecurityToken and writes
it with JwtSecurityTokenHandler; the key kind (symmetric from a made-up test
string, or a fresh RSA key), the key id and the algorithm are chosen by arguments. SDK
11.0.100; the runtimeconfig asks for Microsoft.NETCore.App 10.0.0 and the only 10.0 runtime
installed is 10.0.15; Windows PowerShell 5.1.26100.
Frequently asked
- What does IDX10634 Unable to create the SignatureProvider mean?
- The key and the algorithm in the SigningCredentials do not fit together. In the test an RSA key with HS256 and a symmetric key with RS256 both threw it.
- Why does IDX10634 say SecurityKey: 'Null'?
- That place holds the key id. In the test the keys without an id printed 'Null', and an RSA key given the id rsa1 printed SecurityKey: 'rsa1'.
- How do I sign a JWT with RS256 in .NET?
- In the test, an RsaSecurityKey from RSA.Create(2048) passed to SigningCredentials with the algorithm string RS256 (from the alg=RS256 argument) wrote a token whose header says RS256.
More decoded errors in the Fixes category. A symmetric key that is too short for HS256 gives IDX10653 instead.