Posts

Post not yet marked as solved
0 Replies
480 Views
Getting issue while doing merchant validation from windows server behind load balancer. "System.IO.IOException: The decryption operation failed, see inner exception.\r\n ---> System.ComponentModel.Win32Exception (0x80090326): The message received was unexpected or badly formatted.\r\n --- End of inner exception stack trace ---\r\n at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](TIOAdapter adapter, Memory`1 buffer)\r\n at System.Net.Http.HttpConnection.InitialFillAsync(Boolean async)\r\n at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)" Please anyone can help here code snippet : // POST the data to create a valid Apple Pay merchant session. string json = JsonSerializer.Serialize(request); string path = "apple-pay-cert.pem"; string jsonfilepath = _configuration.GetSection("ApplePay").GetValue<string>("MerchantCertificateFileName"); if (!string.IsNullOrEmpty(jsonfilepath)) { path = _hostingEnvironment.ContentRootFileProvider.GetFileInfo(jsonfilepath)?.PhysicalPath; } var cert = new X509Certificate2(path, "", X509KeyStorageFlags.UserKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable); var sslOptions = new SslClientAuthenticationOptions(); var shHandler = new SocketsHttpHandler { MaxConnectionsPerServer = 100, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, PooledConnectionLifetime = TimeSpan.FromMinutes(3), ConnectTimeout = TimeSpan.FromSeconds(100), PooledConnectionIdleTimeout = TimeSpan.FromSeconds(60), ResponseDrainTimeout = TimeSpan.FromSeconds(60), }; if (cert != null) { shHandler.SslOptions = new SslClientAuthenticationOptions() { ClientCertificates = new X509CertificateCollection(), }; shHandler.SslOptions.ClientCertificates.Add(cert); shHandler.SslOptions.LocalCertificateSelectionCallback = (object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers) => cert; } ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var httpClient = new HttpClient(shHandler); using var content = new StringContent(json, Encoding.UTF8, MediaTypeNames.Application.Json); using var response = await httpClient.PostAsync(requestUri, content, cancellationToken); response.EnsureSuccessStatusCode(); // Read the opaque merchant session JSON from the response body. using var stream = await response.Content.ReadAsStreamAsync(); return await JsonDocument.ParseAsync(stream, cancellationToken: cancellationToken);
Posted
by GymNation.
Last updated
.