public void ShouldDecryptMessage() { var message = JweMessage.FromEncryptedString( CardInfoEncryptedMessage, new List <X509Certificate2> { IssuerEncryptionCert.GetP12Cert() }, new DevJweCryptoPolicy()); var cardInfoRequest = message.GetDecryptedJsonObjectAs <GetCardInfoRequest>(); cardInfoRequest.Should().NotBeNull(); cardInfoRequest.Pan.Should().Be("1234567890123456"); cardInfoRequest.TransactionType.Should().Be("Browser Based (2.0)"); cardInfoRequest.Service.Should().Be("RSA_CLIENT"); cardInfoRequest.RsaSessionId.Should().Be("1122334455667788"); cardInfoRequest.TimeStamp.Should().Be("20190530052056"); cardInfoRequest.Version.Should().Be("3.1"); cardInfoRequest.PurchaseAttributes.Amount.Should().Be("100.00"); cardInfoRequest.PurchaseAttributes.MerchantName.Should().Be("Merchant Name 1"); cardInfoRequest.PurchaseAttributes.Currency.Should().Be("USD"); cardInfoRequest.PurchaseAttributes.MerchantCountryCode.Should().Be("UK"); }
public void ShouldBeValidSignature() { var message = JweMessage.FromEncryptedString( CardInfoEncryptedMessage, new List <X509Certificate2> { IssuerEncryptionCert.GetP12Cert() }, new DevJweCryptoPolicy()); message.IsSignatureValidAndTrusted().Should().BeTrue(); }
public void ShouldEncryptMessage() { var encryptedToken = JweMessage.CreateFromClearText( "This is a test...", IssuerEncryptionCert.GetP12Cert(), new List <X509Certificate2> { IssuerEncryptionCert.GetP12Cert() }); encryptedToken.Should().NotBeNull(); }
private static void EncryptResponse(StringBuilder buffer, Success successResponse) { Console.WriteLine("======================================================================="); Console.WriteLine($"Responding with:\n{JsonConvert.SerializeObject(successResponse)}"); var encrypted = JweMessage.CreateFrom( successResponse, ClientEncryptionCert, new List <X509Certificate2> { IssuerSigningCert }); Console.WriteLine("======================================================================="); Console.WriteLine($"Responding with encrypted Payload:\n{encrypted}"); buffer.AppendLine(encrypted); }
public override async Task <InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding effectiveEncoding) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (effectiveEncoding == null) { throw new ArgumentNullException(nameof(effectiveEncoding)); } var request = context.HttpContext.Request; using (var reader = new StreamReader(request.Body, effectiveEncoding)) { try { var message = await reader.ReadToEndAsync(); Console.WriteLine("======================================================================="); Console.WriteLine($"Received POST request: Encrypted Payload:\n{message}"); var rsaRequest = JweMessage.FromEncryptedString( message, new List <X509Certificate2> { IssuerEncryptionCert }, new DevJweCryptoPolicy() ).GetDecryptedJsonObjectAs <FetchAvailableAliasesRequest>(); Console.WriteLine("======================================================================="); Console.WriteLine($"Received POST request: Decrypted Payload:\n{JsonConvert.SerializeObject(rsaRequest)}"); return(await InputFormatterResult.SuccessAsync(rsaRequest)); } catch { return(await InputFormatterResult.FailureAsync()); } } }
public void RoundTripEncryptAndDecryptMessageShouldBeLossless() { var jweMessage = JweMessage.CreateFrom <GetCardInfoRequest>( CardInfoMessage, IssuerEncryptionCert.GetP12Cert(), new List <X509Certificate2> { IssuerEncryptionCert.GetP12Cert() }); jweMessage.Should().NotBeNull(); var decryptedMessage = JweMessage.FromEncryptedString <GetCardInfoRequest>( jweMessage, new List <X509Certificate2> { IssuerEncryptionCert.GetP12Cert() }, new DevJweCryptoPolicy()); decryptedMessage.Should().BeEquivalentTo(CardInfoMessage); }
public static Success WrapResponse <T>(JweMessage response) { return(new Success { SuccessObject = response.GetDecryptedJsonObjectAs <T>() }); }