using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Tokens;
using System.Collections.Generic;
using System.Security.Claims;
using System.Security.Cryptography;
static void Main(string[] args)
var key = new RsaSecurityKey(RSA.Create(2048));
var privateKey = key.Rsa.ExportRSAPrivateKey();
var publicKey = key.Rsa.ExportSubjectPublicKeyInfo();
var signing = new SigningCredentials(key, SecurityAlgorithms.RsaSha512);
var handler = new JsonWebTokenHandler();
SigningCredentials signingCredentials = new SigningCredentials(key, "RSA512");
var now = DateTime.UtcNow;
var descriptor = new SecurityTokenDescriptor
Expires = now.AddHours(24),
Subject = new ClaimsIdentity(new List<Claim> { new Claim("email", "dotnet@email.com") }),
SigningCredentials = signing
string jwtToken = handler.CreateToken(descriptor);
Console.WriteLine(jwtToken);
Console.WriteLine("Private");
Console.WriteLine($"-----BEGIN RSA PRIVATE KEY-----\r\n{System.Convert.ToBase64String(privateKey)}\r\n-----END RSA PRIVATE KEY-----");
Console.WriteLine("Public");
Console.WriteLine($"-----BEGIN PUBLIC KEY-----\r\n{System.Convert.ToBase64String(publicKey)}\r\n-----END PUBLIC KEY-----");