7

I have to read a private key, and this key is on pvk format. I use X509Certificate2 class, but i this class i have only public key access. How can I get a private key from pvk file?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Luiz Costa
  • 1,515
  • 2
  • 12
  • 12

3 Answers3

4

Luiz, you need to combine the CER and PVK into a single PFX file, then import the file as a cert so that when you load the X509Cert the PrivateKey will be there. See Decrypt with PrivateKey X.509 Certificate.

Community
  • 1
  • 1
Peter
  • 9,643
  • 6
  • 61
  • 108
0

You can use this command to combine them.

pvk2pfx -spc CA.cer -pvk CA.pvk -pfx CA.pfx

Decrypt with PrivateKey X.509 Certificate

Community
  • 1
  • 1
0

http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.privatekey.aspx

How about this ?

Have in mind:

Currently this property supports only RSA or DSA keys, so it returns either an RSACryptoServiceProvider or a DSACryptoServiceProvider object. If no private key is associated with the certificate, a null reference (Nothing in Visual Basic) is returned

anthares
  • 11,070
  • 4
  • 41
  • 61
  • This doesn't address the question. The link shows how to read the PrivateKey from an X509Cert if it's already present, but not how to load it from a pvk file. – Peter Oct 11 '12 at 02:38