I need to send the certificate along with a private key to an API endpoint. I can't do it using PKCS12 as they only accept PEM and DER format. Is there a way to send them using HttpsUrlConnection
? For example, in curl this would be curl -k -X POST --key private.key --cert certificate.pem --url
.
I am kinda new to all of this, so I am wondering if I should really send them in every request or should these be installed on the server and they'll be automatically sent when the API requests them.
For now, I have this snippet:
URL url = new URL("endpoint");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setDoOutput(true);
EDIT: This question shouldn't be closed because Innovationchef provided a really good explanation of mutual TLS that is not explained in the other similar question.