private void Init() { var builder = new JsonWebKeyBuilder(); using (var rsa = RSA.Create()) { var sig = builder.NewSign("1", new[] { KeyOperations.Sign, KeyOperations.Verify }).SetAlg(rsa, RSA256SignHandler.ALG_NAME).Build(); _jsonWebKeys = new[] { sig }; } }
private static IEnumerable <JsonWebKey> ExtractJsonWebKeys(Table table) { var builder = new JsonWebKeyBuilder(); var jwks = new List <JsonWebKey>(); foreach (var record in table.Rows) { var type = record["Type"]; var kid = record["Kid"]; var algName = record["AlgName"]; JsonWebKey jwk = null; switch (type) { case "SIG": if (algName.StartsWith("ES")) { using (var ec = new ECDsaCng()) { jwk = builder.NewSign(kid, new[] { KeyOperations.Sign, KeyOperations.Verify }).SetAlg(ec, algName).Build(); } } else if (algName.StartsWith("HS")) { using (var hmac = new HMACSHA256()) { jwk = builder.NewSign(kid, new[] { KeyOperations.Sign, KeyOperations.Verify }).SetAlg(hmac, algName).Build(); } } else { using (var rsa = RSA.Create()) { jwk = builder.NewSign(kid, new[] { KeyOperations.Sign, KeyOperations.Verify }).SetAlg(rsa, algName).Build(); } } break; case "ENC": using (var rsa = RSA.Create()) { jwk = builder.NewEnc(kid, new[] { KeyOperations.Encrypt, KeyOperations.Decrypt }).SetAlg(rsa, algName).Build(); } break; } jwks.Add(jwk); } return(jwks); }