I am using Jose-Jwt license on C# and I have the following code:
private string DecodeJWT(string token)
{
string privateKeyPath = ConfigurationManager.AppSettings["PrivateKey"];
var privateRSA = RsaProviderFromPrivateKeyInPemFile(privateKeyPath);
string json = Jose.JWT.Decode(token,privateRSA, Jose.JweAlgorithm.RSA_OAEP, Jose.JweEncryption.A256GCM);
return json;
}
private RSACryptoServiceProvider RsaProviderFromPrivateKeyInPemFile(string privateKeyPath)
{
using (TextReader privateKeyTextReader = new StringReader(System.IO.File.ReadAllText(privateKeyPath)))
{
PemReader pr = new PemReader(privateKeyTextReader);
RSAParameters rsaParams = DotNetUtilities.ToRSAParameters((RsaPrivateCrtKeyParameters)pr.ReadObject());
RSACryptoServiceProvider csp = new RSACryptoServiceProvider();
csp.ImportParameters(rsaParams);
return csp;
}
}
However I didn't manage to decrypt the encrypted string. It returns the same encrypted string after decoding. Can anyone advise what I might have done wrong? I am actually following suggestions from this Q/A
It doesn't seem to work for me. :(