How to read a private key from pvk file in C#?
-
20-09-2019 - |
Question
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?
Solution
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.
OTHER TIPS
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
You can use this command to combine them.
pvk2pfx -spc CA.cer -pvk CA.pvk -pfx CA.pfx