I am trying to export a cert without the private key as as BASE-64 encoded file, same as exporting it from windows. When exported from windows I am able to open the .cer file in notepad.
When I try the following and open on notepad I get binary data...I think it is...not readable.
X509Certificate2 cert = new X509Certificate2("c:\\myCert.pfx", "test", X509KeyStorageFlags.Exportable);
File.WriteAllBytes("c:\\testcer.cer", cert.Export(X509ContentType.Cert));
I tried removing the 'X509KeyStorageFlags.Exportable" but that doesn't work. Am I missing something?
Edit - I tried
File.WriteAllText("c:\\testcer.cer",Convert.ToBase64String(cert.Export(X509ContentType.Cert)))
and that seems to work, however, missing the "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----"
openssl pkcs12 -in importPath -nokeys -passin pass:
- this works on both linux and windows openssl binaries.