JWT error IDX10634: Unable to create the SignatureProvider C#

No idea what that error message means, but it doesn't matter I think, because your code is logically wrong. RSA is assymetric algorithm, but you are trying to use SymmetricSecurityKey with it.

So either use another (symmetric) signature algorithm (and ensure that your key size is valid for this algorithm), for example:

// adjust key size
private string unencoded_key = "CaptainDeadpool!";
private string encoded_key = "CaptainDeadpool!";
// ...
SigningCredentials = new SigningCredentials(
    new SymmetricSecurityKey(secret), 
    SecurityAlgorithms.HmacSha256Signature)

Or provide valid key, for example:

private readonly RSA _rsa;
public TokenManager() {
    // import instead of creating new, if necessary
    _rsa = new RSACryptoServiceProvider(2048);            
}
// ...

SigningCredentials = new SigningCredentials(
    new RsaSecurityKey(_rsa), 
    SecurityAlgorithms.RsaSha256Signature)

I had the same problem when using hmacSha256. if your security key is too short, you may receive that error. I increased the size of the secret secureKey and that resolved my problem.

 var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("You_Need_To_Provide_A_Longer_Secret_Key_Here"));

Tags:

C#

Jwt