0

I have code which gets a collection of certs as base64 and write it as a pfx file. But I need as a cert collection to iterate it and find the right cert for my logic.

File.WriteAllBytes(cert.pfx, colecctionofcertinbytes); // I dont want this to treat collection of cert as one cert and want to load it as a collection instead of a single cert X509Certificate2 cert = new X509Certificate2(colecctionofcertinbytes); // will this add it as a collection or a single cert? x509Certificatecollection.Add(cert);

Swa
  • 19
  • 4

1 Answers1

1
X509Certificate2Collection collection = new X509Certificate2Collection();
collection.Import(certPath, certPass, X509KeyStorageFlags.PersistKeySet);
bartonjs
  • 30,352
  • 2
  • 71
  • 111
Swa
  • 19
  • 4
  • Be careful with PersistKeySet: https://stackoverflow.com/questions/36867243/what-is-the-impact-of-the-persistkeyset-storageflag-when-importing-a-certifica/38150435#38150435 – bartonjs Feb 14 '22 at 22:52
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 15 '22 at 00:06