public async Task Get_Key_By_Id() { var keySet = await JWKSet.GetAsync(this.keySetUri); var key = keySet["hs-256"]; Assert.IsNotNull(key); Assert.AreEqual(key.Algorithm, "HS256"); Assert.AreEqual(key.Use, "sig"); Assert.AreEqual(key.Type, "oct"); string value; Assert.IsTrue(key.TryGetValue("k", out value)); Console.Write(value); }
public async Task Verify_HS256_Algorithm_Serialization() { var keySet = await JWKSet.GetAsync(this.keySetUri); var key = keySet["hs-256"]; var token = new JsonWebToken { Issuer = "joe", ExpirationTime = 1300819380 }; token.AddClaim("http://example.com/is_root", true); var serializer = new JWSCompactSerializer(new HS256Algorithm(key)); var strToken = serializer.Serialize(token.ToJson()); var deserializedToken = serializer.Deserialize(strToken); Assert.AreEqual(token.ToJson(), deserializedToken.ToJson()); }
public async Task Verify_RS512_Algorithm_Serialization() { var keySet = await JWKSet.GetAsync(this.keySetUri); var key = keySet["rsa-512"]; var token = new JsonWebToken { Issuer = "joe", ExpirationTime = 1300819380 }; token.AddClaim("http://example.com/is_root", true); var header = new JoseHeader() { JwkSetUrl = this.keySetUri, KeyId = "rsa-512" }; var serializer = new JWSCompactSerializer(new RS512Algorithm(privateKey: key)); var strToken = serializer.Serialize(token.ToJson(), header); var deserializedToken = await serializer.DeserializeAsync(strToken); Assert.AreEqual(token.ToJson(), deserializedToken.ToJson()); }
internal async Task <CryptographicKey> GetPublicKeyAsync() { if (this.JsonWebKey != null) { if (!string.IsNullOrWhiteSpace(this.KeyId) && string.CompareOrdinal(this.KeyId, this.JsonWebKey.Id) != 0) { throw new InvalidCryptographicKeyException("KeyId header and JWK Id missmatch"); } return(this.JsonWebKey); } else if (this.JwkSetUrl != null && !string.IsNullOrWhiteSpace(this.KeyId)) { var set = await JWKSet.GetAsync(this.JwkSetUrl); return(set[this.KeyId]); } else if (this.X509Url != null || this.X509CertificateChain != null) { return(new CryptographicKey(this.X509Url, this.X509CertificateChain, this.X509Thumbprint)); } throw new KeyNotFoundException("No CryptographicKey found in JOSE header"); }