Problem
Like many others, I am trying to export the private key associated with my .cer
file to convert to .pfx
. There are a number of hacked solutions e.g. How to export private key from Windows Certificate Manager?, http://terenceluk.blogspot.com/2020/10/export-certificate-that-does-not-allow.html
but I wanted to focus particularly on https://www.yuenx.com/2022/certificate-security-export-cert-with-non-exportable-private-key-marked-as-not-exportable-windows-pki/ since it does not appear to require any 3rd party tools. Following the instructions there,
Attempts
I am able to export what seems to be my private key. So, I attempted to create a .key
file from the private key information in the generated xml-formatted .reg
file (by copying the data in the <BA>
tag into the .key
file as such):
-----BEGIN RSA PRIVATE KEY-----
<BA> tag content
-----END RSA PRIVATE KEY-----
and then create the pfx
file using openssl:
openssl pkcs12 -export -out test.pfx -inkey test.key -in test.cer
where test.cer
is the certificate exported from the Windows Certificate Store. However, I get the following error:
openssl pkcs12 -export -out test.pfx -inkey test.key -in test.cer
unable to load private key
10208:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto\asn1\tasn_dec.c:1149:
10208:error:0D06C03A:asn1 encoding routines:asn1_d2i_ex_primitive:nested asn1 error:crypto\asn1\tasn_dec.c:713:
10208:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:crypto\asn1\tasn_dec.c:646:Field=version, Type=RSAPrivateKey
10208:error:04093004:rsa routines:old_rsa_priv_decode:RSA lib:crypto\rsa\rsa_ameth.c:142:
10208:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto\asn1\tasn_dec.c:1149:
10208:error:0D06C03A:asn1 encoding routines:asn1_d2i_ex_primitive:nested asn1 error:crypto\asn1\tasn_dec.c:713:
10208:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:crypto\asn1\tasn_dec.c:646:Field=version, Type=PKCS8_PRIV_KEY_INFO
10208:error:0907B00D:PEM routines:PEM_read_bio_PrivateKey:ASN1 lib:crypto\pem\pem_pkey.c:88:
There are two explanations for this error and I don't know how to diagnose either:
- I am not providing the right encryption tag in the header/footer of the
.key
file - The
<BA>
tag content is not actually the private key.
If the problem is 1), what would be the correct header/footer?
If the problem is 2), what is that content? Is it the public key for the .cer
file?