Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create SSLContext from private key and cer files

Tags:

java

ssl

pem

cer

I have two files:

  • mycer.cer
  • mykey.key

I need to create a SslContext to connect to another server via SSL using Java. I'm trying to find out how I can create the SslContext object directly from those files.

This post may be duplicated, but I tried to find a clear explanation with an example to create the SslContext, but didn't find something clear.

like image 719
Marwan Jaber Avatar asked May 11 '17 16:05

Marwan Jaber


People also ask

Can I generate certificate from private key?

You can use OpenSSL to create a private key and a certificate signing request (CSR) that can be transformed into a certificate after it is signed by a certificate authority (CA).

How do I generate a public key from a private key?

You cannot generate private key from public key but you can generate public key from the private key using puttygen. As @alfasin mentioned if you could generate the private key from public key then RSA would be useless and this would make you vulnerable to attack.


1 Answers

Get a certificate in p12 format, as far I know you can not use cert file, there are utilities to do that (like openssl) or the source (from where you generated downloaded the certificate) can give you a p12 format.

openssl pkcs12 -export -in mycer.crt -inkey mykey.key -out mycer.p12 -name "mycer"

And then check the below url, it should contain the information you want.

Java HTTPS client certificate authentication

Hopefully it helps!

like image 177
A Paul Avatar answered Sep 28 '22 01:09

A Paul