How can I convert a private key file from Java into .net x509Certificate2

旧城冷巷雨未停 提交于 2019-11-29 12:27:52

It's probably not a "hash" of the private key. It's most likely the private key in PKCS#8 format.

You can use the openssl command line tool to create a PKCS#12 keystore that should then be able to be used to construct an X509Certificate2 object.

First you will likely have to convert your private key from DER to PEM format, which can also be done in openssl:

openssl rsa -in pkcs8privatekey.der -inform der -out privatekey.pem

Then create the PKCS#12 keystore with:

openssl pkcs12 -export -name myalias -in mycert.crt -inkey privatekey.pem -out keystore.p12

Finally, you should be able to import this into X509Certificate2 object:

X509Certificate2 cert = X509Certificate2("C:\Path\keystore.p12", "password");

you can use the key tool UI. You need to know the type of the certificate they gave you , typically either a JKS key of PEM.

The following commands turn this into a format usable in windows:

Convert the private key from pkcs8/DER to a PEM file format

openssl pkcs8 -nocrypt -in dealerPrivate.key -inform der -outform pem -out private.pem

Convert the certificate from x509/DER to a PEM file format

openssl x509 -inform der -in dealerCertificate.x509 -out public.pem

Merge the two files into a pkcs12 file – you will be prompted for password to protect the p12 with

openssl pkcs12 -export -inkey private.pem -in public.pem -out mycert.p12

pkcs12 can be used directly in windows.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!