Lab 08: Security — JCA/JCE

Time: 60 minutes | Level: Architect | Docker: docker run -it --rm zchencow/innozverse-java:latest bash


Overview

The Java Cryptography Architecture (JCA) and Extension (JCE) provide a provider-based cryptography framework. Master EC P-256 key generation, ECDSA signatures, ECDH key agreement, PBKDF2 key derivation, AES-GCM encryption, and KeyStore management.


Step 1: JCA Provider Architecture

JCA Provider Model:
  Application

  Security.getProvider("SunEC") / "SunJCE" / "SunJSSE"

  ┌───▼──────────────────────────────────────────┐
  │  Provider (SunEC, Bouncy Castle, PKCS#11...) │
  │  - KeyPairGenerator("EC")                     │
  │  - Signature("SHA256withECDSA")               │
  │  - KeyAgreement("ECDH")                       │
  │  - Cipher("AES/GCM/NoPadding")               │
  │  - SecretKeyFactory("PBKDF2WithHmacSHA256")   │
  └──────────────────────────────────────────────┘

Step 2: EC P-256 Key Pair Generation


Step 3: ECDSA Signatures

💡 ECDSA signatures are non-deterministic by default (random k). For deterministic ECDSA use RFC 6979 (available in Bouncy Castle).


Step 4: ECDH Key Agreement


Step 5: PBKDF2 Key Derivation

💡 Store: Base64(salt) + ":" + iterations + ":" + Base64(derivedKey). Never store just the hash — always include salt and iteration count.


Step 6: AES-GCM Authenticated Encryption


Step 7: KeyStore — PKCS#12


Step 8: Capstone — Full JCA Demo

📸 Verified Output:


Summary

Algorithm
Class
Standard

EC P-256 keygen

KeyPairGenerator("EC")

NIST FIPS 186-4

ECDSA sign/verify

Signature("SHA256withECDSA")

RFC 6090

ECDH key agreement

KeyAgreement("ECDH")

RFC 5114

Password hashing

SecretKeyFactory("PBKDF2WithHmacSHA256")

RFC 8018, 600k iterations

Symmetric encryption

Cipher("AES/GCM/NoPadding")

NIST SP 800-38D

Keystore format

KeyStore("PKCS12")

RFC 7292

Secure random

SecureRandom

NIST SP 800-90A

Key derivation

HKDF via Mac("HmacSHA256")

RFC 5869

Last updated