public async Task <string> BuildClientToken(OAuthClient client, JwsPayload jwsPayload, string sigAlg, string encAlg, string enc) { var jwt = await Sign(jwsPayload, sigAlg); if (string.IsNullOrWhiteSpace(encAlg)) { return(jwt); } var jsonWebKeys = await client.ResolveJsonWebKeys(_httpClientFactory); var jsonWebKey = jsonWebKeys.FirstOrDefault(j => j.Use == Usages.ENC && j.Alg == encAlg); if (jsonWebKey == null) { return(jwt); } return(_jweGenerator.Build(jwt, encAlg, enc, jsonWebKey)); }
public void When_Build_Jwe_Then_Can_Decrypt_Into_Jws() { const string payload = "xml"; // ARRANGE InitializeFakeObjects(); JsonWebKey rsaJsonWebKey; using (var rsa = RSA.Create()) { rsaJsonWebKey = new JsonWebKeyBuilder().NewEnc("keyId", new[] { KeyOperations.Encrypt }).SetAlg(rsa, RSAOAEPCEKHandler.ALG_NAME).Build(); } // ACT var encrypted = _jweGenerator.Build(payload, RSAOAEPCEKHandler.ALG_NAME, A192CBCHS384EncHandler.ENC_NAME, rsaJsonWebKey); var decrypted = _jweGenerator.Decrypt(encrypted, rsaJsonWebKey); // ASSERT Assert.Equal(payload, decrypted); }