Created
July 30, 2019 16:25
-
-
Save zerda/5f3b30bd576835c8a8a9ebf659c50979 to your computer and use it in GitHub Desktop.
Convert an RSA to JsonWebKey format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// nuget package reference with: | |
// - System.IdentityModel.Tokens.Jwt | |
using System; | |
using System.Security.Cryptography; | |
using Newtonsoft.Json; | |
using Microsoft.IdentityModel.Tokens; | |
static void Main(string[] args) { | |
var provider = new RSACryptoServiceProvider(2048); | |
var key = new RsaSecurityKey(provider.ExportParameters(true)); | |
var jwk = JsonWebKeyConverter.ConvertFromRSASecurityKey(key); | |
jwk.KeyId = "authentication"; | |
jwk.Use = "sig"; | |
jwk.Alg = "RS256"; | |
var json = JsonConvert.SerializeObject(jwk); | |
Console.WriteLine(json); | |
} |
afarber
commented
Nov 26, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment