I am send a CertificateRequest object to an REST API in base64string format by using below code and namespace System.Security.Cryptography.X509Certificates
.
string certificateRequestBase64String = string.Empty;
// Generate a new RSA key pair.
using (RSA rsa = RSA.Create(keyLength))
{
// Create a new X509CertificateRequest object.
CertificateRequest certificateRequest = new CertificateRequest("x-subject", rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
// Add any additional extensions you want to include.
certificateRequest.CertificateExtensions.Add(new X509BasicConstraintsExtension(false, false, 0, true));
// Convert the request to a PEM-encoded string.
certificateRequestBase64String = Convert.ToBase64String(certificateRequest.CreateSigningRequest());
}
Then I am using below code to trying to convert back this base 64 string to CertificateRequest
X509Certificate2 x509Certificate2 = new X509Certificate2(Convert.FromBase64String(certificateRequestBase64String));
It throws Cannot find the requested object error.
Is there any other way to get this done?