0

I'm trying to invoke a rest API with SpringBoot RestTemplate. It was given to me the API address, and from the browser I could export the .cer file.

However, I've read some about what should I do, and It's been confusing.

Some can give me a snippet or insight about this. The ApI is exposed securely. I should use this certificate to invoke the API securely. Do I have to generate pks file from .cer file?

Thanks in advance.

rui
  • 79
  • 2
  • 7

1 Answers1

0

Similar question was asked and answered before, see here: https://stackoverflow.com/a/63426053/6777695

The rest template uses Apache http client under the covers. You need to provide a custom SSLContext to it. The above link has examples for the client configuration and the creation of the SSLContext.

I would recommend to create a jks or p12 file and import the cer file. Afterwords YouCan supply this p12 or jks file to the SSLContext builders/factories.

An example command for creating and importing could be the following snippet:

keytool -keystore truststore.jks -importcert -file /path/to/server.cer -alias server
Hakan54
  • 3,121
  • 1
  • 23
  • 37