As in Postman we have certificate and key file, how do I validate the KEY file using c# or MVC. I have tried adding the below code but seems like for the KEY file we've some other code to write. Please suggest some help.
string base64cert = Convert.ToBase64String(File.ReadAllBytes(pemFilePath));
var cert = new X509Certificate2(Convert.FromBase64String(base64cert), certAuthCode);
cert.PrivateKey = null;
handler.ClientCertificates.Add(cert);
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.SslProtocols = SslProtocols.Tls12;
handler.ClientCertificates.Add(new X509Certificate2(crtFilePath));
//For Key File Path
handler.ClientCertificates.Add(new X509Certificate2(crtKeyPath));
Amit MohantyPosted Jun 28, 2023, 11:08 AM
Try this
Akaash Chintamani MeherPosted Jun 28, 2023, 10:59 AM
@Amit Mohanty - Thanks for the response. I think the ImportPkcs8PrivateKey() method is available in higher version of .Net because I'm getting error for the same. Could you please provide any alternatives.
Amit MohantyPosted Jun 28, 2023, 10:48 AM
Please take a look at the code below; it may be helpful to you.