Search code examples
c#.netx509certificate2pfx

How to Read PFX Certificate from local machine Store with C#


I want to read .PFX certificate from Local Machine Store.

I use bellow code to read .CER file from store.

 X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection certificateCollection = store.Certificates.Find(X509FindType.FindBySerialNumber, certificateSerialNo, true);
if (certificateCollection.Count == 1)
        {
           //Do something  
        }

So is their any way to read .PFX certificate from STORE ?


Solution

  • It is my mistake. You can read .PFX certicicate as the same way as .CER,

    So the Keypoints are.

    1. .PFX contaning both the key.
    2. In Order to import and export and read .PFX file from a folder in order to verify sign required "Password" of the .PFX file.
    3. In order to read .PFX file (Private key) from STORE not required any password.