3

I'm having trouble with objEnroll.CreatePFX where the only return type is string, and what I need is a binary output comparable to what happens when I open the Certificates MMC and export a PFX.

This is important because I need the original PFX format so I can import the private key into OSX and iPhone.

    CX509Enrollment objEnroll = new CX509Enrollment();
   objEnroll.InitializeFromTemplateName(
                X509CertificateEnrollmentContext.ContextUser,
                templateName);
   // ...
   objEnroll.Enroll();
   string pfxString = objEnroll.CreatePFX("q", PFXExportOptions.PFXExportEEOnly, EncodingType.XCN_CRYPT_STRING_BINARY);

What is the correct way to set the EncodingType so that it can be properly converted into a binary output? (Similar to a Windows certificate export )

makerofthings7
  • 60,103
  • 53
  • 215
  • 448

1 Answers1

3

Just write the base64 string into a file

System.IO.File.WriteAllText("MyFile.pfx", pfxString);

Windows will handle the PFX.

You can also convert base64 to binary using

System.IO.File.WriteAllBytes("MyFile.pfx", System.Convert.FromBase64String(pfxString));
Daniel Fisher lennybacon
  • 3,865
  • 1
  • 30
  • 38