Host API Service on HTTPS from EC2/Cloud

Dr. Rajeev Rathor
2 min readJun 26, 2023

Advantage of Hosting Service on HTTPs instead of Http:

HTTPS is HTTP with encryption and verification. The only difference between the two protocols is that HTTPS uses TLS (SSL) to encrypt normal HTTP requests and responses, and to digitally sign those requests and responses. As a result, HTTPS is far more secure than HTTP.|
1. Encryption Layer enabled
2. Data protection
3. Ranking Boost with Google
4. Protection against Phishing
5. Leveraged to gain customer trust
6. Payments Card Industry Compliance
7. Maybe slower to load only in the initial phases
8. Certification and Validation have costs associated with them
9. Post validation redirection needed as a one-time activity

Type of
Keygen Tool Specific to Server:
keytool -genkeypair -alias baeldung -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore baeldung.p12 -validity 36500 -ext “SAN:c=DNS:localhost,IP:15.23.152.177”

Note: -ext is important parameter is used to restrict validation for Server Specific. This certificate will remain valid only for given IP or domain name. If this Params is absent then your CA will work for localhost but fail for Server hosted over cloud or network.

Spring API Server based on HTTPs:

generated certificate or Keystore file in Spring Application’s resource folder and add following application.properties file.
# The format used for the keystore. It could be set to JKS in case it is a JKS

server.port=443
server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:keystore/baeldung.p12
server.ssl.key-store-password=password
server.ssl.key-alias=baeldung

How to Test Https API from Postman
Test Https based API is not usual to test. First Postman should be setup with self-signed certificates that encrypt and Decrypt the request and response. refer Screenshoots.
Open Postman and Go to Settings and Open Certificate tab and upload keystore/ Certificate.

Host Https from AWS EC2 instance:

Consume API from Java Http Client:

Consume API from Android App:

--

--

Dr. Rajeev Rathor

PhD [IOT+AI], M.Tech [CSE] , B.Tech, 14 Years exp s from Product Development in Java, Backend, Data Engineering, IOT plaeform