2

how can i install two certificates (pfx with password) during my setup is installing on pc? I need Two certificates located on personal->certificates because desktop program is used for all users on this pc.

I'm using .net 3.5

Thanks.

enter image description here

user3486836
  • 163
  • 1
  • 1
  • 7
  • Would you mind defining "my setup" more closely? Do you already use a setup software of a specific vendor or are you in the planning phase of creating a setup project? – ZiggZagg Apr 13 '18 at 16:49

1 Answers1

1

This below will extract the Public & Private key from the .PFX file and parse it into an X509Certificate2 object (X509Certificate type does not support Private keys and is unable understand V2 & V3 properties). You then pass X509Certificate2 object to the local certificate repository which is currently set to LocalMachine as I'm guessing that's where you want it according to the image you attached.

X509Certificate2 cert = new X509Certificate2(@"C:\key.pfx", "test1234", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet); //Saves in the local machine store - accessible for all users

  using (var store = new X509Store(StoreName.My, StoreLocation.LocalMachine))
  {
     store.Open(OpenFlags.ReadWrite); //Set to Write - You need Admin Permissions
     store.Add(cert); //Add Private Cert to Store
  }

I recommend that you read this post by Paul Stovell before diving head first as permissions could be nightmare especially within a domain environment (Active Directory).

Kitson88
  • 2,889
  • 5
  • 22
  • 37