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); }
public async Task <string> Decrypt(string jwe) { if (string.IsNullOrWhiteSpace(jwe)) { throw new ArgumentNullException(nameof(jwe)); } var protectedHeader = _jweGenerator.ExtractHeader(jwe); if (protectedHeader == null) { return(string.Empty); } var jsonWebKey = await _jsonWebKeyRepository.FindJsonWebKeyById(protectedHeader.Kid); if (jsonWebKey == null) { return(string.Empty); } return(_jweGenerator.Decrypt(jwe, jsonWebKey)); }