Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Export cert in pfx format

NET to export a certificate from the cert store into a PFX file. I'm trying to use the X509certificate2.Export method with the X509ContentType.Pfx flag set, but am unsure how to handle the returned byte array and output it correctly to file.

Any help appreciated.

like image 364
J Hunt Avatar asked Jul 24 '09 10:07

J Hunt


1 Answers

Judging by the date, you may have already figured this out, but all you have to do is write the returned byte array directly to a file:

byte[] certData = cert.Export(X509ContentType.Pfx, "MyPassword");
File.WriteAllBytes(@"C:\MyCert.pfx", certData);
like image 184
Aaronaught Avatar answered Sep 19 '22 03:09

Aaronaught