Jose.JWT.Encode gives Invalid algorithm specified Exception

1.4k Views Asked by At

I have Using .Net45 framework I want the token from the certificate file.

var privateKey=new X509Certificate2("my-key.p12", "password", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet).PrivateKey as RSACryptoServiceProvider;
string token=Jose.JWT.Encode(payload, privateKey, JwsAlgorithm.RS256);

The above code gives Invalid algorithm Exception..

But the same time when i move to net4.6 it works good with the following code.

var privateKey=new X509Certificate2("my-key.p12", "password").GetRSAPrivateKey();
string token=Jose.JWT.Encode(payload, privateKey, JwsAlgorithm.RS256);

Could you please give any suggestion for this issue ?

1

There are 1 best solutions below

0
Vel On

Re-import key will work.

There are different ways to solve it, easiest one is to re-import key to obtain valid provider implementation.

Please see the below URL for further clarification.

https://github.com/dvsekhvalnov/jose-jwt#rsacryptoserviceprovider