Definition
- TLS (Transport Layer Security) is a protocol that provides encryption, authentication, and integrity for network communication.
- HTTPS is HTTP wrapped in TLS, ensuring all data between client and server is encrypted.
- Symmetric encryption uses one key for both encryption and decryption (AES-256); fast, used for data transfer.
- Asymmetric encryption uses a key pair (public key encrypts, private key decrypts; RSA, ECDSA); used for key exchange during TLS handshake.
- Encryption at rest encrypts data stored on disk (database files, backups, logs) so it is unreadable without the decryption key.
- Certificate is a digital document that binds a public key to a domain name, signed by a Certificate Authority (CA).
Think of the National Bank of India sending a sealed courier package. TLS is the armored van that transports the package: nobody on the road can open it. The TLS handshake is the process where the sender and receiver agree on a lock combination using a special exchange so that even if someone watches the exchange, they cannot figure out the combination. Encryption at rest is the vault where the package is stored after delivery: even if someone breaks into the building, the vault door requires a separate key.
Understanding the Concepts
How does the TLS handshake work?
The TLS handshake establishes a secure connection. TLS 1.3 completes in one round trip (1-RTT), compared to two round trips in TLS 1.2.
- Client Hello: The client sends supported TLS versions, cipher suites, and a random number.
- Server Hello: The server selects a cipher suite, sends its certificate (containing the public key), and a random number.
- Key Exchange: Using the server's public key, both sides derive a shared session key.
- Finished: Both sides send encrypted "finished" messages to verify the handshake.
- Data Transfer: All subsequent data is encrypted with the shared session key (symmetric, AES-256).
package com.bank.security;
public class TLSHandshakeDemo {
public static void main(String[] args) {
System.out.println("TLS 1.3 Handshake:");
System.out.println();
System.out.println("1. Client -> Server: ClientHello");
System.out.println(" TLS 1.3, cipher suites: [TLS_AES_256_GCM_SHA384]");
System.out.println(" Key share: ECDHE public key");
System.out.println();
System.out.println("2. Server -> Client: ServerHello + Certificate");
System.out.println(" Selected: TLS_AES_256_GCM_SHA384");
System.out.println(" Certificate: nationalbank.in (signed by DigiCert)");
System.out.println(" Key share: ECDHE public key");
System.out.println();
System.out.println("3. Both derive session key from ECDHE exchange");
System.out.println(" Session key: AES-256 symmetric key");
System.out.println();
System.out.println("4. All data encrypted with AES-256-GCM");
System.out.println(" Request: POST /api/transfers (encrypted)");
System.out.println(" Response: {\"status\": \"success\"} (encrypted)");
}
}
TLS 1.3 Handshake:
1. Client -> Server: ClientHello
TLS 1.3, cipher suites: [TLS_AES_256_GCM_SHA384]
Key share: ECDHE public key
2. Server -> Client: ServerHello + Certificate
Selected: TLS_AES_256_GCM_SHA384
Certificate: nationalbank.in (signed by DigiCert)
Key share: ECDHE public key
3. Both derive session key from ECDHE exchange
Session key: AES-256 symmetric key
4. All data encrypted with AES-256-GCM
Request: POST /api/transfers (encrypted)
Response: {"status": "success"} (encrypted)
How do you configure HTTPS in a Spring Boot application?
# application.yml
server:
port: 8443
ssl:
enabled: true
key-store: classpath:keystore.p12
key-store-password: ${KEYSTORE_PASSWORD}
key-store-type: PKCS12
protocol: TLS
enabled-protocols: TLSv1.3
ciphers:
- TLS_AES_256_GCM_SHA384
- TLS_CHACHA20_POLY1305_SHA256
# Generate a self-signed certificate for development
keytool -genkeypair \
-alias nationalbank \
-keyalg RSA \
-keysize 2048 \
-storetype PKCS12 \
-keystore keystore.p12 \
-storepass changeit \
-validity 365 \
-dname "CN=localhost, O=National Bank of India"
package com.bank.security;
public class HTTPSConfigDemo {
public static void main(String[] args) {
System.out.println("HTTPS configuration:");
System.out.println(" Port: 8443 (HTTPS)");
System.out.println(" Protocol: TLS 1.3");
System.out.println(" Cipher: TLS_AES_256_GCM_SHA384");
System.out.println(" Keystore: PKCS12 format");
System.out.println();
System.out.println("Production setup:");
System.out.println(" Certificate from Let's Encrypt or DigiCert");
System.out.println(" TLS terminated at load balancer (ALB/Nginx)");
System.out.println(" Internal traffic: mTLS between microservices");
}
}
HTTPS configuration:
Port: 8443 (HTTPS)
Protocol: TLS 1.3
Cipher: TLS_AES_256_GCM_SHA384
Keystore: PKCS12 format
Production setup:
Certificate from Let's Encrypt or DigiCert
TLS terminated at load balancer (ALB/Nginx)
Internal traffic: mTLS between microservices
How does encryption at rest work?
Encryption at rest protects data stored on disk. If an attacker steals a hard drive, a database backup, or an S3 bucket, the data is unreadable without the encryption key.
package com.bank.security;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import java.security.SecureRandom;
import java.util.Base64;
public class EncryptionAtRestDemo {
public static void main(String[] args) throws Exception {
// Generate AES-256 key
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(256);
SecretKey key = keyGen.generateKey();
// Sensitive data: account number and balance
String sensitiveData = "SAV2001:Rajesh:75000.00";
// Encrypt
byte[] iv = new byte[12];
new SecureRandom().nextBytes(iv);
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, key, new GCMParameterSpec(128, iv));
byte[] encrypted = cipher.doFinal(sensitiveData.getBytes());
String encryptedBase64 = Base64.getEncoder().encodeToString(encrypted);
System.out.println("Original: " + sensitiveData);
System.out.println("Encrypted: " + encryptedBase64);
// Decrypt
cipher.init(Cipher.DECRYPT_MODE, key, new GCMParameterSpec(128, iv));
byte[] decrypted = cipher.doFinal(encrypted);
System.out.println("Decrypted: " + new String(decrypted));
}
}
Original: SAV2001:Rajesh:75000.00
Encrypted: a3F5RjdmK2xNZUhwTzlJVXdBbHc9PQ==
Decrypted: SAV2001:Rajesh:75000.00
How is symmetric encryption different from asymmetric encryption?
| Aspect | Symmetric (AES) | Asymmetric (RSA/ECDSA) |
|---|---|---|
| Keys | One shared key | Public key + private key |
| Speed | Fast (hardware-accelerated) | Slow (1000x slower) |
| Use case | Encrypting data (TLS payload, disk) | Key exchange, digital signatures |
| Key length | 128 or 256 bits | 2048+ bits (RSA), 256 bits (ECDSA) |
| Problem | How to share the key securely | Slower, used only for small data |
| TLS role | Encrypts all data after handshake | Used during handshake only |
What are common mistakes with TLS and encryption?
Mistake 1: Not enforcing HTTPS redirect
Wrong: the application accepts both HTTP and HTTPS. Credentials sent over HTTP are visible to anyone on the network.
// WRONG: application accepts HTTP on port 8080
// A user accidentally types http://nationalbank.in
// Password travels in plain text
Correct: redirect all HTTP to HTTPS.
package com.bank.security;
public class HTTPSRedirectDemo {
public static void main(String[] args) {
System.out.println("WRONG: Accept both HTTP and HTTPS");
System.out.println(" http://nationalbank.in/login -> password in plain text!");
System.out.println();
System.out.println("CORRECT: Redirect HTTP to HTTPS");
System.out.println(" http://nationalbank.in/login -> 301 -> https://nationalbank.in/login");
System.out.println(" HSTS header: Strict-Transport-Security: max-age=31536000");
System.out.println(" Browser remembers: always use HTTPS for this domain");
}
}
WRONG: Accept both HTTP and HTTPS
http://nationalbank.in/login -> password in plain text!
CORRECT: Redirect HTTP to HTTPS
http://nationalbank.in/login -> 301 -> https://nationalbank.in/login
HSTS header: Strict-Transport-Security: max-age=31536000
Browser remembers: always use HTTPS for this domain
What is mutual TLS (mTLS)?
In standard TLS, only the server presents a certificate. In mTLS, both the client and server present certificates and verify each other. This is used for service-to-service communication in banking microservices.
package com.bank.security;
public class MTLSDemo {
public static void main(String[] args) {
System.out.println("Standard TLS (browser to API):");
System.out.println(" Server presents certificate -> client verifies");
System.out.println(" Client does NOT present certificate");
System.out.println();
System.out.println("Mutual TLS (service to service):");
System.out.println(" Transfer-service presents certificate -> Account-service verifies");
System.out.println(" Account-service presents certificate -> Transfer-service verifies");
System.out.println(" Both sides trust each other's CA");
System.out.println();
System.out.println("Banking use case:");
System.out.println(" All internal microservice communication uses mTLS");
System.out.println(" Istio service mesh automates mTLS certificate management");
}
}
Standard TLS (browser to API):
Server presents certificate -> client verifies
Client does NOT present certificate
Mutual TLS (service to service):
Transfer-service presents certificate -> Account-service verifies
Account-service presents certificate -> Transfer-service verifies
Both sides trust each other's CA
Banking use case:
All internal microservice communication uses mTLS
Istio service mesh automates mTLS certificate management
What layers of encryption does a banking system need?
package com.bank.security;
public class EncryptionLayersDemo {
public static void main(String[] args) {
System.out.println("Banking encryption layers:");
System.out.println();
System.out.println("1. In transit (TLS 1.3):");
System.out.println(" Browser <-> API Gateway: HTTPS");
System.out.println(" Service <-> Service: mTLS");
System.out.println(" Service <-> Database: TLS");
System.out.println();
System.out.println("2. At rest (AES-256):");
System.out.println(" Database: RDS encryption enabled");
System.out.println(" S3 buckets: SSE-KMS encryption");
System.out.println(" EBS volumes: encrypted");
System.out.println(" Backups: encrypted with separate key");
System.out.println();
System.out.println("3. Application-level (field encryption):");
System.out.println(" PAN card number: encrypted in the database column");
System.out.println(" Aadhaar number: encrypted before storage");
System.out.println(" Key stored in AWS KMS, not in the application");
}
}
Banking encryption layers:
1. In transit (TLS 1.3):
Browser <-> API Gateway: HTTPS
Service <-> Service: mTLS
Service <-> Database: TLS
2. At rest (AES-256):
Database: RDS encryption enabled
S3 buckets: SSE-KMS encryption
EBS volumes: encrypted
Backups: encrypted with separate key
3. Application-level (field encryption):
PAN card number: encrypted in the database column
Aadhaar number: encrypted before storage
Key stored in AWS KMS, not in the application
What should a senior engineer know?
- Perfect Forward Secrecy (PFS). TLS 1.3 uses ephemeral Diffie-Hellman (ECDHE) for every session. Even if the server's private key is compromised later, past session keys cannot be derived. All past communications remain confidential.
- Certificate pinning. For mobile banking apps, pin the server's certificate or public key in the app. This prevents man-in-the-middle attacks even if the attacker has a valid certificate from a compromised CA.
- Key management with AWS KMS. Store encryption keys in AWS KMS or Azure Key Vault. The keys never leave the HSM. Your application calls KMS to encrypt/decrypt. This provides audit trails, automatic rotation, and hardware-level security.
- Column-level encryption. For PCI-DSS and banking compliance, encrypt specific sensitive columns (PAN, Aadhaar, account numbers) at the application level before storing in the database. This protects data even from database administrators.
- TLS termination points. In production, TLS is typically terminated at the load balancer (ALB, Nginx). Internal traffic between the load balancer and application can use mTLS or plain HTTP on a private network. Understand the tradeoffs.
What are common interview follow-up questions?
- What is the difference between TLS 1.2 and TLS 1.3?
- How does certificate chaining work?
- What is HSTS and why is it important?
- How do you handle certificate expiration in production?
- What is the difference between encryption at rest and encryption in transit?
Visual Overview
TLS 1.3 Handshake (1-RTT)
===========================
Client Server
────── ──────
│ ClientHello │
│ + key_share (ECDHE) ──────> │
│ │
│ <────── │ ServerHello
│ │ + key_share (ECDHE)
│ │ + Certificate
│ │ + Finished
│ │
│ Finished ──────> │
│ │
│ ====== Encrypted data ====== │
│ POST /api/transfers ──────> │
│ <────── │ 200 OK {"status":"success"}
Encryption Layers in Banking
==============================
Browser ──TLS 1.3──> API Gateway ──mTLS──> Transfer Service
│
├──TLS──> PostgreSQL (at rest: AES-256)
├──TLS──> Redis
└──TLS──> Kafka
Data at rest: AES-256-GCM
Data in transit: TLS 1.3
Sensitive fields: Application-level encryption (KMS)
Key Takeaway
Encryption in a banking application operates at three layers. TLS encrypts data in transit: every API call, every database query, and every message between microservices travels through an encrypted channel. Without TLS, an attacker on the same network can read passwords, account numbers, and transaction details in plain text. TLS 1.3 is the current standard, completing the handshake in one round trip with strong cipher suites and perfect forward secrecy.
Encryption at rest protects data on disk. If an attacker steals a database backup, an EBS volume, or an S3 bucket, the data is unreadable without the encryption key. AWS RDS, S3, and EBS all support transparent encryption. For sensitive fields like PAN card numbers and Aadhaar numbers, use application-level encryption with keys managed in AWS KMS.
The TLS handshake is a carefully designed dance. The client and server use asymmetric encryption (ECDHE) to agree on a shared session key. Then they switch to symmetric encryption (AES-256-GCM) for the actual data transfer, because symmetric encryption is thousands of times faster. The server proves its identity with a certificate signed by a trusted Certificate Authority.
For microservice communication within the banking platform, mutual TLS (mTLS) ensures both sides verify each other's identity. An Istio service mesh can automate certificate issuance, rotation, and mTLS enforcement across all services.
One sentence to remember: TLS protects data in transit with the handshake and symmetric encryption, AES-256 protects data at rest on disk, and together they ensure banking data is unreadable without the correct keys.
---