X509Store pfx certificate issues RRS feed

  • Question

  • Hi,

    I'm using the following code to retrieve a previously entered pfx certificate to the local machine certificate store;

    X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);

                store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);

                X509Certificate2Collection certCollection =

                  store.Certificates.Find(X509FindType.FindByTimeValid, DateTime.Now, false);

                X509Certificate2Enumerator enumerator = certCollection.GetEnumerator();

                X509Certificate2 cert = null;

                while (enumerator.MoveNext())


                    if (enumerator.Current.FriendlyName.Contains("keyname") == 0)


                        cert = enumerator.Current;




                byte[] pkcs10 = cert.Export(X509ContentType.Pkcs12, "pwd");


    This is returning a byte[] (pkcs10) with a length of  3542 and I can continue to use this key to sign documents.


    For production I want to move this key into the local machine keystore, so importing the key in the same fashion and amending the code to 

    X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); 

    I again run the code can receive an error when attempting to sign the document.  Looking at the size of the key it is now 3623 bytes.  


    Any ideas??

    Monday, August 22, 2011 8:40 AM

All replies