I want to generate a JWT Token in .Net 4.5 using an asymmetric key that I provide myself, but I am running into a few issues with the System.IdentityModel.Tokens.Jwt, version 4.0.3.
Preferably I would create my own 2048 keys, like provider allows me to do. The RSA.Create() constructor creates 1024 keys.
using (RSACryptoServiceProvider provider = new RSACryptoServiceProvider(2048))
{
var publicPrivate = provider.ToXmlString(true);
var publicKeyOnly = provider.ToXmlString(false);
var stuff = provider.ExportParameters(true);
signingCredentials = new SigningCredentials(new RsaSecurityKey(RSA.Create()), SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest); //no idea how to pull the key out of here.
}
In many examples one can drop RSAParameters into the RsaSecurityKey constructor, but now it only takes the RSA.Create() constructor (with optional string parameter) The following code snip comes from https://stackoverflow.com/a/38233644 Note that in this example the RSAParameters go nicely into the RsaSecurityKey constructor, which I cannot do with my version, I am restricted to using RSA.Create, it seams.
// NOTE: Replace this with your actual RSA public/private keypair!
var provider = new RSACryptoServiceProvider(2048);
var parameters = provider.ExportParameters(true);
// Build the credentials used to sign the JWT
var signingKey = new RsaSecurityKey(parameters); //not an option for me, unfortunately