c# 3.0 - Trouble installing certificate from .pfx file -


i trying install certificate on local machine (win server 2003) x509certificate2 class in c# test console application. when install certificate following code, fine:

var serviceruntimemachinecertificatestore = new x509store(storename.root, storelocation.localmachine); serviceruntimemachinecertificatestore.open(openflags.readwrite); cert = new x509certificate2(certificatepath); serviceruntimemachinecertificatestore.add(cert); serviceruntimemachinecertificatestore.close(); 

problem is, private key of certificate not persisted, when installed without x509keystorageflags.persistkeyset. tried instanciate certificate (the private key has no password, pass in empty string):

var serviceruntimemachinecertificatestore = new x509store(storename.root, storelocation.localmachine); serviceruntimemachinecertificatestore.open(openflags.readwrite); cert = new x509certificate2(certificatepath, "", x509keystorageflags.persistkeyset); serviceruntimemachinecertificatestore.add(cert); serviceruntimemachinecertificatestore.close(); 

but trying instanciate certificate throws system.security.cryptography.cryptographicexception "failed load certificate: specified network password not correct.", though private key has no password.

if import certificate in microsoft management console without specifying password works great.

does know how programmatically?

if try create instance of x509certificate2 empty password on windows xp or windows 2003, "failed load certificate: specified network password not correct." exception thrown.

if can, try create certificate password not empty. should fine.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -