开发者

Not able to import private key in certificate store on Windows7 desktop

I used the following code to import certifica开发者_如何学运维te 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 :-(


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜