I'm trying to log in to a web server over SSL from a client application.
I don't want the username and password to be sent over plaintext, so I would like to encrypt my traffic and subsequent REST calls using the SSL certificate provided by the web server.
So far, my code retrieves the certificate from the server, and from that I can retrieve the public key.
public void testConnectionTo(String aURL) throws Exception {
URL destinationURL = new URL(aURL);
HttpsURLConnection conn = (HttpsURLConnection) destinationURL
.openConnection();
conn.connect();
Certificate[] certs = conn.getServerCertificates();
for (Certificate cert : certs) {
System.out.println(cert.getPublicKey());
}
This returns 3 different RSA public Keys. Which one do I use, and how (in pseudo code/code) do I use this public key to encrypt my outbound traffic?
https://protocol, your traffic is automatically and transparently encrypted. What exactly are you trying to achieve? Getting sever certificates is mostly to check if you accept them.