1

I used the following code to import certificate WITH the password/private key in WinXp desktop.

Recently I migrated to windows7 and now I am not able to import the private key, although the certificate gets imported in the store.

What could be wrong here ? Any help is deeply appreciated.

X509Store store = new X509Store(StoreName.My);

X509Certificate2 certificate = new X509Certificate2("certFileName", "password" ); store.Open(OpenFlags.ReadWrite); store.Add(certificate); store.Close()

Noticed that even if I type in the wrong password, the certificate still gets imported and private key field shows null, obviously. But with correct password it should get populated :-(

Harkamal
  • 11
  • 3

1 Answers1

0

Check if you have correct permissions :

How to set read permission on the private key file of X.509 certificate from .NET

You can also try adding storage flags to the certificate constructor:

X509Certificate2 certificate = new X509Certificate2("certFileName", "password", X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);

Setting this permmission might help: https://serverfault.com/questions/48124/disabling-strong-private-key-encryption-on-a-personal-certificate

Community
  • 1
  • 1
zby_szek
  • 568
  • 1
  • 6
  • 9