Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

Say I have an X.509 cert and a private key that corresponds to it. I can import X.509 certs easily enough into Windows but what about private keys?

Is the only way I can do that by converting both the cert and the private key to a "Personal Information Exchange (PKCS #12)" file and importing that?

Maybe this question would be better on superuser.com? Either way, thanks!

share|improve this question
add comment

4 Answers

A PKCS12 (*.p12, or *.pfx) is absolutely the easy way. There are quite a few common tools out there for combining a key pair and certificate into a p12. My favorite is OpenSSL, since it works on every OS I've ever needed to use it on and it's reasonably standards compliant. Here's a diverse collection of pages on how, although mileage will vary based upon how your key pair and certificate are currently stored.

Also - most devices with an export capability will offer a PKCS12 generation option if the settings allow key export - its more or less the standard for most PKI enabled applications, and the few cases where this is not the norm (Java for example), there is still usually a conversion or export capability.

One note - if you have a case where your key is on a hardware token or module, you can still reference it from the Microsoft Cert Store - you just need to import the certificate and instruct Microsoft on where the key is stored... to do this, you need to follow the device's instructions for updating the certificate store.

share|improve this answer
add comment

In Windows, you can have private keys "by themselves". Programmatically, you use CryptAquireContext() to access a key "by name". The CryptoAPI contains many functions which allow you to import and use keys, independently of certificates.

However, there is no existing graphical interface or file format for handling private keys, and applications do not use keys by name. They use certificates. Certificates, in Windows, are stored "elsewhere", but each certificate in the "My" store can optionally contain a link to a corresponding private key (the link would really be a CSP name, and name of a container within that CSP). This maps to what is expected in various protocols. For instance, in SSL, when the server requests a client authentication with a private key, it actually asks for a certificate: the client must present a certificate, and then, only then, demonstrate that it also has access to the corresponding private key.

Thus, in practice, certificates and keys "live together" and keys are reached only through certificates. A certificate and its private key travel together, and this means a PKCS#12 file (aka "PFX").

share|improve this answer
add comment

The answer to your question is "Yes". You must convert the X 509 into a PFX and import. There is no separate key store in Windows.

You can convert via OpenSSL with the following command:

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

share|improve this answer
add comment

Pub/priv key pairs should be imported into Windows using a PKCS12 (.p12/pfx) when you're using it as a client certificate. That's all there is to it here...

If you're importing it into IIS that's a bit different, but that doesn't seem to be what you're doing. Just in case - IIS requires a slightly different format than X.509 for its certificates; it requires a PKCS7 instead of generic X.509 because PKCS7 includes the signer certificates, whereas X.509 only has the individual certificate which has been signed. This differs from the typical Apache implemention where the signer certificates are included in a [trusted] cert bundle.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.