š Encryption & Hashing Reference Guide
**Data Security System - Complete Cryptographic Specification**
š Encryption & Hashing Reference Guide
Data Security System - Complete Cryptographic Specification
š Table of Contents
- Password Hashing
- Data Encryption
- End-to-End Encryption
- Sensitive Data Protection
- Key Derivation
- Data Processing Flow
š Password Hashing
Multi-Layer Password Vault (5 Layers)
Storage Format:
$MLP$v1$[salt_b64]$[pepper_id]$[argon2_params]$[encrypted_hmac_hash_b64]
Processing Pipeline:
-
Layer 1: Pepper Application
peppered_password = password ā SYSTEM_PEPPER- Adds server-side secret to password
-
Layer 2: Argon2id Hashing
argon2_hash = Argon2id(peppered_password, salt, m=128MB, t=4, p=8) ā 512-bit hash output- Memory: 131,072 KB (128 MB)
- Iterations: 4
- Parallelism: 8 threads
- Salt: 32 bytes (256-bit)
- Output: 64 bytes (512-bit)
-
Layer 3: AES-256-GCM Encryption
encryption_key = PBKDF2-HMAC-SHA512(salt, 600,000 iterations) encrypted_hash = AES-256-GCM(argon2_hash, encryption_key, iv)- Key size: 256-bit
- IV: 12 bytes (96-bit)
- Tag: 128-bit authentication tag
-
Layer 4: HMAC-SHA512 Signature
hmac_key = PBKDF2-HMAC-SHA512(salt, 600,000 iterations) signature = HMAC-SHA512(encrypted_hash, hmac_key)- Output: 64 bytes (512-bit)
-
Layer 5: Combined Storage
final_output = encrypted_hash || hmac_signature
Legacy Argon2id (Fallback)
Formula:
hash = Argon2id(password, salt, m=131072, t=4, p=8)
Encoded Format:
$argon2id$v=19$m=131072,t=4,p=8$[salt_b64]$[hash_b64]
Parameters:
- Version: 19 (Argon2 v1.3)
- Memory: 131,072 KB (128 MB)
- Iterations: 4 (time cost)
- Parallelism: 8 threads
- Salt: 32 bytes
- Hash output: 64 bytes
š Data Encryption
AES-256-GCM (Authenticated Encryption)
Encryption Formula:
ciphertext = AES-256-GCM(plaintext, key, iv)
output = iv || ciphertext || tag
Parameters:
- Algorithm: AES/GCM/NoPadding
- Key size: 256-bit
- IV length: 12 bytes (96-bit)
- Tag length: 128-bit (authentication)
- Mode: Galois/Counter Mode (GCM)
Format:
[12-byte IV][ciphertext][16-byte auth tag]
Security Properties:
- ā Confidentiality (encryption)
- ā Integrity (authentication tag)
- ā AEAD (Authenticated Encryption with Associated Data)
š End-to-End Encryption
ECDH Key Exchange
Curve: P-384 (secp384r1)
Security Level: 192-bit
Key Generation:
(private_key, public_key) = ECDH_KeyGen(P-384)
Shared Secret Derivation:
shared_secret = ECDH(our_private_key, peer_public_key)
derived_key = HKDF-Extract-Expand(shared_secret, "E2E-AES-KEY", 32)
HKDF (HMAC-based Key Derivation)
Extract Phase:
PRK = HMAC-SHA384(zero_salt, input_key_material)
Expand Phase:
OKM = HMAC-SHA384(PRK, info || 0x01)
key = first_32_bytes(OKM)
Hybrid Encryption (ECIES-style)
Encryption:
ephemeral_keypair = generate_keypair()
shared_secret = ECDH(ephemeral_private, recipient_public)
aes_key = HKDF(shared_secret)
ciphertext = AES-256-GCM(plaintext, aes_key)
output = ephemeral_public || iv || ciphertext || tag
Format:
[97-byte ephemeral_public][12-byte iv][ciphertext][16-byte tag]
š”ļø Sensitive Data Protection
Field-Level Encryption
Encryption:
encrypted_field = "ENC$v1$" + Base64(AES-256-GCM(plaintext, key))
Decryption:
Parse format ā Extract ciphertext ā AES-256-GCM decrypt
Searchable Encryption (Blind Index)
Blind Index Formula:
normalized_input = lowercase(trim(plaintext))
blind_index = Truncate(HMAC-SHA256(normalized_input, index_key), 16)
output = Base64(blind_index)
Properties:
- Allows searching without decryption
- ā ļø Leaks search patterns (use carefully)
- Index size: 16 bytes (128-bit)
Data Masking
Email Masking:
"user@example.com" ā "us****@example.com"
Keep: first 2 chars + domain
Phone Masking:
"1234567890" ā "123*****90"
Keep: first 3 + last 2 digits
ID Masking:
"ID123456789" ā "ID****6789"
Keep: prefix + last 4 chars
š Key Derivation
PBKDF2-HMAC-SHA512
Formula:
derived_key = PBKDF2-HMAC-SHA512(password, salt, iterations=600,000, keylen=32)
Parameters:
- Algorithm: PBKDF2 with HMAC-SHA512
- Iterations: 600,000 (OWASP 2024 recommendation)
- Salt: 32 bytes (256-bit)
- Output: 32 bytes (256-bit key)
Use Cases:
- Password-based encryption keys
- Database password encryption
- AES key derivation
HMAC-SHA512 Signature
Formula:
signature = HMAC-SHA512(message, key)
Properties:
- Output: 64 bytes (512-bit)
- Used for message authentication
- Constant-time verification (timing attack resistant)
š Data Processing Flow
User Registration Flow
1. User enters password
ā
2. Multi-Layer Vault Processing:
password ā pepper ā Argon2id ā AES-GCM ā HMAC ā storage
ā
3. Store in database:
$MLP$v1$[salt]$[pepper_id]$[params]$[encrypted_hash]
User Login Flow
1. User enters password
ā
2. Retrieve stored hash from database
ā
3. Verify:
- Extract salt and parameters
- Recompute: pepper ā Argon2id ā encrypt ā HMAC
- Compare: constant-time comparison
ā
4. Return: Match (ā
) or No Match (ā)
Sensitive Data Storage
1. User data (email, phone, etc.)
ā
2. Encrypt with AES-256-GCM
ā
3. Create blind index (if searchable)
ā
4. Store: "ENC$v1$[ciphertext]" + blind_index
ā
5. Database stores encrypted data
Sensitive Data Retrieval
1. Query by blind index (if searching)
ā
2. Retrieve encrypted field
ā
3. Parse format: "ENC$v1$[ciphertext]"
ā
4. Decrypt with AES-256-GCM
ā
5. Return plaintext to authorized user
š¢ Cryptographic Constants Summary
| Component | Algorithm | Key Size | Parameters |
|---|---|---|---|
| Password Hash | Argon2id | - | m=128MB, t=4, p=8 |
| Password Encrypt | AES-256-GCM | 256-bit | IV=12B, Tag=128b |
| Password HMAC | HMAC-SHA512 | 512-bit | Output=64B |
| Key Derivation | PBKDF2-SHA512 | 256-bit | 600k iterations |
| Data Encryption | AES-256-GCM | 256-bit | IV=12B, Tag=128b |
| E2E Key Exchange | ECDH P-384 | 384-bit | 192-bit security |
| E2E Encryption | AES-256-GCM | 256-bit | Hybrid ECIES |
| Blind Index | HMAC-SHA256 | 256-bit | Truncated 128-bit |
| Salt Generation | SecureRandom | 256-bit | 32 bytes |
šÆ Security Strength Analysis
| Protection Type | Security Level | Notes |
|---|---|---|
| Password Hashing | Maximum | 5-layer defense, memory-hard |
| Data at Rest | Maximum | AES-256-GCM authenticated |
| Data in Transit | Maximum | E2E with ECDH P-384 |
| Key Derivation | Maximum | 600k PBKDF2 iterations |
| Random Generation | Cryptographic | SecureRandom.getInstanceStrong() |
š What Gets Encrypted
Passwords
- Method: Multi-Layer Password Vault (5 layers)
- Storage: Hash only (irreversible)
- Verification: Recompute and compare
Sensitive User Data
- Email addresses: AES-256-GCM + Blind index
- Phone numbers: AES-256-GCM + Blind index
- ID numbers: AES-256-GCM + Masking
- Personal information: AES-256-GCM
Database Credentials
- Method: PBKDF2-HMAC-SHA256 + AES
- Iterations: 310,000
- Storage: Environment variables (encrypted)
š Security Features
- Timing Attack Prevention: Constant-time comparisons
- Memory Safety: Secure wiping of sensitive data
- Perfect Forward Secrecy: Ephemeral keys in E2E
- Authenticated Encryption: GCM mode with integrity tags
- Salt Uniqueness: Cryptographically random per password
- Pepper Protection: Server-side secret (not in database)
- Memory-Hard Hashing: Argon2id resists GPU attacks
- AEAD: Combined confidentiality + integrity
š Mathematical Notation
Key Symbols:
ā= XOR operation||= Concatenationā= Produces/Results inHMAC(k, m)= Hash-based Message Authentication CodeE(k, m)= Encryption with key k and message mD(k, c)= Decryption with key k and ciphertext cH(m)= Hash functionKDF(p, s)= Key Derivation Function with password p and salt s
ā Compliance
- ā OWASP 2024: Password storage guidelines
- ā NIST SP 800-63B: Digital identity guidelines
- ā FIPS 140-2: Cryptographic module standards
- ā PHC Winner: Argon2 (Password Hashing Competition)
- ā NSA Suite B: P-384 curve approved
š ļø Methods & Implementation Logic
CryptoCore.java - Cryptographic Operations
| Method | Parameters | Returns | Logic Flow |
|---|---|---|---|
encryptAesGcm() | plaintext, key | ciphertext | 1. Generate random 12-byte IV<br>2. Configure GCM with 128-bit tag<br>3. Encrypt with AES-256-GCM<br>4. Prepend IV to ciphertext<br>5. Return [IV||ciphertext||tag] |
decryptAesGcm() | ciphertext, key | plaintext | 1. Extract IV (first 12 bytes)<br>2. Extract encrypted data<br>3. Configure GCM parameters<br>4. Decrypt and verify tag<br>5. Return plaintext |
encryptToBase64() | string, key | Base64 | 1. Convert string to UTF-8 bytes<br>2. Call encryptAesGcm()<br>3. Encode to Base64<br>4. Return encoded string |
decryptFromBase64() | ciphertext, key | string | 1. Decode Base64<br>2. Call decryptAesGcm()<br>3. Convert bytes to UTF-8 string<br>4. Return plaintext |
deriveKey() | password, salt, iterations | SecretKey | 1. Create PBKDF2-SHA512 factory<br>2. Configure key spec (256-bit output)<br>3. Generate secret with iterations<br>4. Wrap as AES key<br>5. Return SecretKey |
generateRandomKey() | - | SecretKey | 1. Initialize KeyGenerator (AES)<br>2. Configure 256-bit size<br>3. Use SecureRandom<br>4. Generate key |
hmacSign() | data, key | signature | 1. Initialize HMAC-SHA512<br>2. Set secret key<br>3. Process data<br>4. Return 64-byte signature |
hmacVerify() | data, signature, key | boolean | 1. Compute HMAC of data<br>2. Constant-time compare with signature<br>3. Return match result |
generateSalt() | - | byte[] | 1. Create 32-byte array<br>2. Fill with SecureRandom<br>3. Return salt |
generateSecureToken() | byteLength | String | 1. Generate random bytes<br>2. Encode as URL-safe Base64<br>3. Return token |
constantTimeEquals() | a[], b[] | boolean | 1. Check length equality<br>2. XOR all bytes<br>3. Check if result is zero<br>4. Prevents timing attacks |
wipeMemory() | data[] | void | 1. Overwrite with random bytes<br>2. Fill with zeros<br>3. Clear sensitive data |
xorBytes() | a[], b[] | byte[] | 1. Check length match<br>2. XOR each byte pair<br>3. Return result |
bytesToHex() | bytes[] | String | 1. Iterate each byte<br>2. Format as 2-digit hex<br>3. Return hex string |
CryptoCore Logic:
- All encryption uses authenticated AES-256-GCM
- Random IVs prevent pattern detection
- Memory wiping protects against forensic recovery
- Constant-time operations prevent timing attacks
E2EEncryption.java - End-to-End Encryption
| Method | Parameters | Returns | Logic Flow |
|---|---|---|---|
generateKeyPair() | - | KeyPair | 1. Initialize ECDH KeyPairGenerator<br>2. Configure P-384 curve<br>3. Generate key pair<br>4. Return (private, public) |
exportPublicKey() | PublicKey | String | 1. Get key bytes (X.509 format)<br>2. Encode to Base64<br>3. Return encoded key |
importPublicKey() | base64Key | PublicKey | 1. Decode Base64<br>2. Create X509EncodedKeySpec<br>3. Generate public key<br>4. Return PublicKey |
deriveSharedKey() | privateKey, peerPublicKey | SecretKey | 1. Initialize ECDH KeyAgreement<br>2. Set private key<br>3. Perform key exchange (doPhase)<br>4. Generate shared secret<br>5. Apply HKDF<br>6. Wipe shared secret<br>7. Return AES key |
hkdfExtractExpand() | inputKeyMaterial, info, length | byte[] | 1. Extract: HMAC-SHA384(zero_salt, IKM)<br>2. Expand: HMAC-SHA384(PRK, info||0x01)<br>3. Truncate to length<br>4. Return derived key |
encryptForRecipient() | plaintext, recipientPublicKey | String | 1. Generate ephemeral keypair<br>2. Derive shared secret via ECDH<br>3. Generate random IV<br>4. Encrypt with AES-256-GCM<br>5. Combine [ephemeral_pub||IV||ciphertext]<br>6. Encode to Base64 |
decryptWithPrivateKey() | encryptedData, privateKey | String | 1. Decode Base64<br>2. Extract ephemeral public key<br>3. Extract IV and ciphertext<br>4. Reconstruct ephemeral key<br>5. Derive shared secret<br>6. Decrypt with AES-256-GCM<br>7. Return plaintext |
encryptSymmetric() | plaintext, key | String | 1. Generate random IV<br>2. Configure AES-256-GCM<br>3. Encrypt plaintext<br>4. Prepend IV to ciphertext<br>5. Encode to Base64 |
decryptSymmetric() | encryptedData, key | String | 1. Decode Base64<br>2. Extract IV (first 12 bytes)<br>3. Extract ciphertext<br>4. Decrypt with AES-256-GCM<br>5. Return plaintext |
encryptDeterministic() | plaintext, key | String | 1. Hash plaintext with SHA-256<br>2. Use hash as deterministic IV<br>3. Encrypt with AES-256-GCM<br>4. Return ciphertext (same input ā same output) |
encryptWithAAD() | plaintext, key, aad | String | 1. Generate random IV<br>2. Configure GCM cipher<br>3. Add AAD (authenticated but not encrypted)<br>4. Encrypt plaintext<br>5. Return IV||ciphertext||tag |
decryptWithAAD() | encryptedData, key, aad | String | 1. Decode and parse data<br>2. Extract IV and ciphertext<br>3. Configure cipher with AAD<br>4. Decrypt and verify integrity<br>5. Return plaintext |
E2E Logic:
- ECDH provides forward secrecy (ephemeral keys)
- Hybrid encryption combines asymmetric + symmetric
- P-384 curve provides 192-bit security level
- Perfect Forward Secrecy: each session has unique keys
MultiLayerPasswordVault.java - 5-Layer Password Protection
| Method | Parameters | Returns | Logic Flow |
|---|---|---|---|
hashPassword() | password | String | 1. Generate 32-byte random salt<br>2. Layer 1: Apply pepper via HMAC<br>3. Layer 2: Hash with Argon2id<br>4. Layer 3: Derive encryption key (PBKDF2)<br>5. Encrypt hash with AES-256-GCM<br>6. Layer 4: Derive HMAC key (PBKDF2)<br>7. Sign encrypted hash<br>8. Layer 5: Combine all layers<br>9. Encode as $MLP$v1$...<br>10. Return encoded string |
verifyPassword() | password, storedHash | boolean | 1. Parse MLP format<br>2. Extract salt, params, encrypted data<br>3. Split encrypted hash and HMAC<br>4. Verify HMAC (fail fast if tampered)<br>5. Derive encryption key<br>6. Decrypt stored hash<br>7. Recompute: pepper ā Argon2id<br>8. Constant-time compare hashes<br>9. Return match result |
applyPepper() | password | byte[] | 1. Initialize HMAC-SHA512<br>2. Use system pepper as key<br>3. Process password<br>4. Return peppered bytes |
argon2idHash() | data, salt, memory, iterations, parallelism | byte[] | 1. Build Argon2id parameters<br>2. Set memory (128 MB)<br>3. Set iterations (4)<br>4. Set parallelism (8 threads)<br>5. Generate 64-byte hash<br>6. Return hash |
encryptAesGcm() | plaintext, key | byte[] | 1. Generate random 12-byte IV<br>2. Configure GCM (128-bit tag)<br>3. Encrypt with AES-256<br>4. Prepend IV to ciphertext<br>5. Return encrypted data |
decryptAesGcm() | ciphertext, key | byte[] | 1. Extract IV (first 12 bytes)<br>2. Extract encrypted data<br>3. Configure GCM cipher<br>4. Decrypt and verify tag<br>5. Return plaintext |
hmacSign() | data, key | byte[] | 1. Initialize HMAC-SHA512<br>2. Process data with key<br>3. Return 64-byte signature |
deriveEncryptionKey() | salt | SecretKey | 1. Combine pepper + "ENCRYPTION_KEY_DERIVATION"<br>2. Run PBKDF2-SHA512 (600k iterations)<br>3. Derive 256-bit key<br>4. Return AES key |
deriveHmacKey() | salt | SecretKey | 1. Combine pepper + "HMAC_KEY_DERIVATION"<br>2. Run PBKDF2-SHA512 (600k iterations)<br>3. Derive 256-bit key<br>4. Return HMAC key |
verifyLegacyArgon2() | password, encodedHash | boolean | 1. Parse Argon2id format<br>2. Extract parameters and salt<br>3. Recompute Argon2id hash<br>4. Constant-time compare<br>5. Return match result |
Multi-Layer Vault Logic:
- Pepper (Layer 1): Server secret prevents rainbow tables
- Argon2id (Layer 2): Memory-hard function resists GPUs
- AES Encryption (Layer 3): Encrypts the hash itself
- HMAC (Layer 4): Detects tampering
- PBKDF2 (Layer 5): Derives encryption/HMAC keys
Format: $MLP$v1$[salt]$[pepper_id]$[argon2_params]$[encrypted_hmac_hash]
PasswordSecurityUtil.java - Password Management
| Method | Parameters | Returns | Logic Flow |
|---|---|---|---|
hashPassword() | password | String | 1. Log hashing operation<br>2. If USE_MULTI_LAYER_VAULT enabled:<br>Ā Ā Ā ā Call MultiLayerPasswordVault.hashPassword()<br>3. Else:<br>Ā Ā Ā ā Call hashPasswordArgon2id()<br>4. Return encoded hash |
hashPasswordArgon2id() | password | String | 1. Generate 32-byte random salt<br>2. Configure Argon2id:<br>   ⢠Memory: 128 MB<br>   ⢠Iterations: 4<br>   ⢠Parallelism: 8<br>3. Generate 64-byte hash<br>4. Encode as PHC format<br>5. Return $argon2id$v=19$... |
verifyPassword() | password, encodedHash | boolean | 1. Detect hash format (MLP or Argon2id)<br>2. If MLP format:<br>Ā Ā Ā ā Call MultiLayerPasswordVault.verifyPassword()<br>3. If Argon2id format:<br>Ā Ā Ā ā Call verifyPasswordArgon2id()<br>4. Log verification attempt<br>5. Return match result |
verifyPasswordArgon2id() | password, encodedHash | boolean | 1. Parse encoded hash ($argon2id$...)<br>2. Extract: memory, iterations, parallelism<br>3. Extract: salt and expected hash<br>4. Recompute Argon2id hash<br>5. Constant-time compare<br>6. Return match result |
needsRehash() | encodedHash | boolean | 1. If MLP format: return false (strongest)<br>2. If Argon2id + vault enabled: return true<br>3. If Argon2id parameters outdated: return true<br>4. Otherwise: return false |
encodeHash() | salt, hash | String | 1. Build PHC string format<br>2. Include version (v=19)<br>3. Include parameters (m, t, p)<br>4. Base64 encode salt<br>5. Base64 encode hash<br>6. Return formatted string |
constantTimeEquals() | a[], b[] | boolean | 1. Check length equality<br>2. XOR all byte pairs<br>3. Check if result == 0<br>4. Prevents timing attacks |
Password Security Logic:
- Auto-detects hash format for backward compatibility
- Upgrades weak hashes after successful login
- Constant-time comparison prevents timing attacks
- Audit logging for security monitoring
SensitiveDataProtector.java - PII Encryption
| Method | Parameters | Returns | Logic Flow |
|---|---|---|---|
encryptField() | plaintext | String | 1. Check if plaintext is null/empty<br>2. Call CryptoCore.encryptToBase64()<br>3. Prepend "ENC$v1$" prefix<br>4. Return formatted ciphertext |
decryptField() | encryptedField | String | 1. Check if starts with "ENC$"<br>2. Parse format: split by '$'<br>3. Extract version and ciphertext<br>4. Call CryptoCore.decryptFromBase64()<br>5. Return plaintext |
createBlindIndex() | plaintext | String | 1. Normalize input (lowercase, trim)<br>2. Compute HMAC-SHA256 with index key<br>3. Truncate to 16 bytes (128-bit)<br>4. Encode to Base64<br>5. Return index (allows searching) |
encryptSearchable() | plaintext | EncryptedSearchableField | 1. Call encryptField() for ciphertext<br>2. Call createBlindIndex() for index<br>3. Return object with both values |
encryptEmail() | EncryptedSearchableField | 1. Normalize email (lowercase, trim)<br>2. Call encryptSearchable()<br>3. Return encrypted value + blind index | |
encryptPhoneNumber() | phoneNumber | String | 1. Normalize: remove non-digits<br>2. Call encryptField()<br>3. Return encrypted phone |
encryptIdNumber() | idNumber | EncryptedSearchableField | 1. Normalize: uppercase, remove special chars<br>2. Call encryptSearchable()<br>3. Return encrypted ID + index |
maskEmail() | String | 1. Find @ symbol<br>2. Keep first 2 chars of local part<br>3. Replace rest with <br>4. Keep full domain<br>5. Return: "us@example.com" | |
maskPhoneNumber() | phone | String | 1. Extract only digits<br>2. Keep last 4 digits<br>3. Replace rest with <br>4. Return: "-***-1234" |
maskIdNumber() | idNumber | String | 1. Keep last 4 characters<br>2. Replace rest with *<br>3. Return: "****6789" |
maskName() | name | String | 1. Split by spaces<br>2. Keep first name full<br>3. Mask last name (first char + )<br>4. Return: "John D" |
mightContainPII() | data | boolean | 1. Check email regex pattern<br>2. Check phone regex pattern<br>3. Check SSN pattern<br>4. Check credit card pattern<br>5. Return true if any match |
redactPII() | data | String | 1. Replace emails with [EMAIL REDACTED]<br>2. Replace phones with [PHONE REDACTED]<br>3. Replace SSN with [SSN REDACTED]<br>4. Replace cards with [CARD REDACTED]<br>5. Return sanitized string |
loadOrGenerateKey() | keyName | SecretKey | 1. Check environment variable<br>2. If found: decode Base64<br>3. Else: generate deterministic key<br>4. Wrap as AES SecretKey<br>5. Return key |
generateNewKey() | - | String | 1. Generate 32 random bytes<br>2. Encode to Base64<br>3. Return key string |
Sensitive Data Logic:
- Field encryption: "ENC$v1$[ciphertext]" format
- Blind index: HMAC-based searchable encryption
- Masking: Display-safe partial visibility
- PII detection: Regex-based pattern matching
- Redaction: Safe logging without exposing data
PasswordEncryptor.java - Database Credential Encryption
| Method | Parameters | Returns | Logic Flow |
|---|---|---|---|
main() | args | void | 1. Prompt for MySQL password<br>2. Prompt for master key (32+ chars)<br>3. Generate random 16-byte salt<br>4. Derive encryption key via PBKDF2-SHA256<br>   ⢠310,000 iterations<br>   ⢠256-bit key<br>5. Encrypt password with AES<br>6. Encode to Base64<br>7. Display encrypted credentials<br>8. Show security warnings |
Logic:
- One-time utility to encrypt DB passwords
- Uses PBKDF2-SHA256 with 310k iterations
- Outputs: encrypted password, salt, master key
- Credentials stored as environment variables
š Complete Data Flow Diagrams
User Registration Flow (Detailed)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā USER INPUT: Password "MySecurePass123!" ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā LAYER 1: PEPPER APPLICATION ā
ā ⢠Method: applyPepper(password) ā
ā ⢠Operation: HMAC-SHA512(password, SYSTEM_PEPPER) ā
ā ⢠Output: 64-byte peppered password ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā LAYER 2: ARGON2ID HASHING ā
ā ⢠Method: argon2idHash(peppered_password, salt) ā
ā ⢠Parameters: m=128MB, t=4, p=8, salt=32 bytes ā
ā ⢠Operation: Memory-hard password hashing ā
ā ⢠Output: 64-byte Argon2id hash ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā LAYER 3: KEY DERIVATION ā
ā ⢠Method: deriveEncryptionKey(salt) ā
ā ⢠Operation: PBKDF2-SHA512(pepper+purpose, salt, 600k iters) ā
ā ⢠Output: 256-bit AES encryption key ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā LAYER 3: AES-256-GCM ENCRYPTION ā
ā ⢠Method: encryptAesGcm(argon2_hash, encryption_key) ā
ā ⢠Operation: Generate IV ā Encrypt with GCM ā Add auth tag ā
ā ⢠Output: [IV || encrypted_hash || tag] ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā LAYER 4: HMAC SIGNATURE ā
ā ⢠Method: deriveHmacKey(salt) + hmacSign(encrypted_hash, key) ā
ā ⢠Operation: PBKDF2 key derivation ā HMAC-SHA512 signing ā
ā ⢠Output: 64-byte integrity signature ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā LAYER 5: FINAL ENCODING ā
ā ⢠Method: Combine all components ā
ā ⢠Format: $MLP$v1$[salt]$[pepper_v]$[params]$[enc+hmac] ā
ā ⢠Store in database: users table, password_hash column ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
User Login Flow (Detailed)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā USER INPUT: Login attempt with password ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 1: RETRIEVE STORED HASH ā
ā ⢠Query database: SELECT password_hash FROM users WHERE... ā
ā ⢠Method: UserDAO.getUserByUsername() ā
ā ⢠Result: $MLP$v1$... or $argon2id$... ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 2: FORMAT DETECTION ā
ā ⢠Method: verifyPassword() auto-detects format ā
ā ⢠If MLP: ā MultiLayerPasswordVault.verifyPassword() ā
ā ⢠If Argon2id: ā verifyPasswordArgon2id() ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 3: PARSE STORED HASH ā
ā ⢠Split by '$' delimiter ā
ā ⢠Extract: salt, pepper_version, argon2_params, encrypted_data ā
ā ⢠Parse parameters: memory, iterations, parallelism ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 4: VERIFY HMAC (Fail Fast) ā
ā ⢠Method: deriveHmacKey(salt) + constantTimeEquals() ā
ā ⢠Split encrypted_data into: [encrypted_hash][hmac_signature] ā
ā ⢠Compute HMAC of encrypted_hash ā
ā ⢠Compare with stored HMAC (constant-time) ā
ā ⢠If mismatch: RETURN FALSE (tampered data) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 5: DECRYPT STORED HASH ā
ā ⢠Method: deriveEncryptionKey(salt) + decryptAesGcm() ā
ā ⢠Derive encryption key via PBKDF2 ā
ā ⢠Extract IV from encrypted_hash ā
ā ⢠Decrypt with AES-256-GCM ā
ā ⢠Verify authentication tag ā
ā ⢠Output: Original Argon2id hash (64 bytes) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 6: RECOMPUTE PASSWORD HASH ā
ā ⢠Method: applyPepper() + argon2idHash() ā
ā ⢠Apply pepper to login password ā
ā ⢠Run Argon2id with extracted parameters ā
ā ⢠Generate 64-byte hash ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 7: CONSTANT-TIME COMPARISON ā
ā ⢠Method: constantTimeEquals(computed_hash, stored_hash) ā
ā ⢠XOR all byte pairs ā
ā ⢠Check if result == 0 ā
ā ⢠Prevents timing attacks ā
ā ⢠Return: true (match) or false (no match) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 8: SECURITY AUDIT LOGGING ā
ā ⢠Method: SecurityAuditLogger.log() ā
ā ⢠Log: timestamp, username, IP, result (success/failure) ā
ā ⢠If failed: increment failure counter ā trigger alerts ā
ā ⢠If success: check needsRehash() ā upgrade if needed ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Sensitive Data Encryption Flow
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā INPUT: User email "john.doe@example.com" ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 1: NORMALIZATION ā
ā ⢠Method: encryptEmail() ā normalize ā
ā ⢠Operation: lowercase + trim ā
ā ⢠Result: "john.doe@example.com" ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā PARALLEL PROCESSING ā ā
āāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāāāāāā ā
ā ā PATH A: ENCRYPTION ā ā PATH B: BLIND INDEX ā ā
ā ā ā ā ā ā
ā ā ⢠encryptField() ā ā ⢠createBlindIndex() ā ā
ā ā ⢠AES-256-GCM ā ā ⢠HMAC-SHA256 ā ā
ā ā ⢠Random IV ā ā ⢠Truncate to 128-bit ā ā
ā ā ⢠Generate tag ā ā ⢠Base64 encode ā ā
ā ā ā ā ā ā
ā ā Output: ā ā Output: ā ā
ā ā "ENC$v1$[ciphertext]" ā ā "Ab12Cd34Ef56..." ā ā
ā āāāāāāāāāāāāā¬āāāāāāāāāāāāāā āāāāāāāāāāāā¬āāāāāāāāāāāāāāā ā
ā ā ā ā
āāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāā
ā ā
āāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 3: STORE IN DATABASE ā
ā ⢠Column 1: email_encrypted = "ENC$v1$..." ā
ā ⢠Column 2: email_index = "Ab12Cd34Ef56..." ā
ā ⢠Allows searching by index without decryption ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Data Retrieval and Display Flow
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā QUERY: Search user by email ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 1: CREATE SEARCH INDEX ā
ā ⢠Method: createBlindIndex("search@example.com") ā
ā ⢠Normalize input ā HMAC-SHA256 ā Truncate ā Base64 ā
ā ⢠Result: "Xy78Zw..." ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 2: DATABASE QUERY ā
ā ⢠SQL: SELECT * FROM users WHERE email_index = 'Xy78Zw...' ā
ā ⢠Returns: Encrypted records matching the index ā
ā ⢠No decryption needed for searching ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 3: DECRYPT FOR AUTHORIZED USER ā
ā ⢠Method: decryptField("ENC$v1$...") ā
ā ⢠Parse format ā Extract ciphertext ā Decode Base64 ā
ā ⢠Extract IV ā AES-256-GCM decrypt ā Verify tag ā
ā ⢠Result: "john.doe@example.com" ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 4: MASK FOR DISPLAY ā
ā ⢠Method: maskEmail("john.doe@example.com") ā
ā ⢠Keep first 2 chars + domain ā
ā ⢠Replace middle with *** ā
ā ⢠Display: "jo***@example.com" ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
E2E Encryption Flow (ECIES)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā SENDER: Wants to send encrypted message to RECIPIENT ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 1: GENERATE EPHEMERAL KEYPAIR ā
ā ⢠Method: generateKeyPair() ā
ā ⢠Curve: P-384 (ECDH) ā
ā ⢠Output: (ephemeral_private, ephemeral_public) ā
ā ⢠Note: Keys are temporary, used only for this message ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 2: ECDH KEY EXCHANGE ā
ā ⢠Method: deriveSharedKey(ephemeral_private, recipient_public) ā
ā ⢠Operation: ECDH(our_private, their_public) ā
ā ⢠Apply HKDF: Extract-Expand with "E2E-AES-KEY" ā
ā ⢠Wipe shared secret from memory ā
ā ⢠Output: 256-bit AES key ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 3: ENCRYPT MESSAGE ā
ā ⢠Method: AES-256-GCM ā
ā ⢠Generate random IV (12 bytes) ā
ā ⢠Encrypt plaintext with derived key ā
ā ⢠Add authentication tag (128-bit) ā
ā ⢠Output: [ciphertext || tag] ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā STEP 4: PACKAGE FOR TRANSMISSION ā
ā ⢠Combine: [ephemeral_public || IV || ciphertext || tag] ā
ā ⢠Encode to Base64 ā
ā ⢠Result: "MIGb..." (ready to send) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā RECIPIENT: DECRYPT MESSAGE ā
ā ⢠Method: decryptWithPrivateKey() ā
ā ⢠Decode Base64 ā Parse components ā
ā ⢠Extract ephemeral_public (97 bytes for P-384) ā
ā ⢠ECDH: Derive shared key with own private key ā
ā ⢠AES-256-GCM: Decrypt with derived key ā
ā ⢠Verify authentication tag ā
ā ⢠Return: Original plaintext message ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š Method Category Summary
Encryption Methods (11)
encryptAesGcm()- Core AES-256-GCM encryptiondecryptAesGcm()- Core AES-256-GCM decryptionencryptToBase64()- String encryptiondecryptFromBase64()- String decryptionencryptField()- Database field encryptiondecryptField()- Database field decryptionencryptSearchable()- Searchable encryption with blind indexencryptForRecipient()- Hybrid E2E encryption (ECIES)decryptWithPrivateKey()- Hybrid E2E decryptionencryptSymmetric()- Pre-shared key encryptiondecryptSymmetric()- Pre-shared key decryption
Hashing Methods (5)
hashPassword()- Multi-layer password hashingverifyPassword()- Password verificationargon2idHash()- Argon2id memory-hard hashinghmacSign()- HMAC-SHA512 signaturehmacVerify()- HMAC verification
Key Management Methods (7)
generateKeyPair()- ECDH keypair generationderiveKey()- PBKDF2 key derivationderiveSharedKey()- ECDH shared secret derivationgenerateRandomKey()- Random AES key generationgenerateSalt()- Cryptographic salt generationgenerateSecureToken()- Random token generationloadOrGenerateKey()- Key loading/generation
Data Protection Methods (8)
createBlindIndex()- Searchable encryption indexmaskEmail()- Email masking for displaymaskPhoneNumber()- Phone maskingmaskIdNumber()- ID number maskingmaskName()- Name maskingmightContainPII()- PII detectionredactPII()- PII redaction for logsapplyPepper()- Pepper application
Security Utilities (6)
constantTimeEquals()- Timing attack preventionwipeMemory()- Secure memory wipingxorBytes()- XOR operationbytesToHex()- Hex encodinghexToBytes()- Hex decodingneedsRehash()- Hash upgrade detection
š”ļø CIA Triad Implementation
Confidentiality (Data Privacy)
| Implementation | Method/Class | How It Works |
|---|---|---|
| Password Protection | MultiLayerPasswordVault | 5-layer encryption: pepper ā Argon2id ā AES-256-GCM ā HMAC ā PBKDF2 prevents unauthorized access |
| Field Encryption | SensitiveDataProtector.encryptField() | AES-256-GCM encrypts emails, phones, IDs before database storage |
| E2E Encryption | E2EEncryption.encryptForRecipient() | ECDH P-384 + AES-256-GCM ensures only recipient can decrypt |
| Access Control | SecureSessionManager | Token-based session management limits data access to authorized users |
| Data Masking | SensitiveDataProtector.maskEmail() | Displays masked data (jo***@example.com) to unauthorized viewers |
| Memory Protection | CryptoCore.wipeMemory() | Overwrites sensitive data in RAM after use |
| Logging Redaction | SensitiveDataProtector.redactPII() | Removes PII from logs: [EMAIL REDACTED], [PHONE REDACTED] |
Integrity (Data Accuracy & Trustworthiness)
| Implementation | Method/Class | How It Works |
|---|---|---|
| Authentication Tags | AES-256-GCM | 128-bit tag verifies data hasn't been tampered, fails decryption if modified |
| HMAC Signatures | MultiLayerPasswordVault.hmacSign() | HMAC-SHA512 signs encrypted hashes, detects tampering before decryption |
| Hash Verification | PasswordSecurityUtil.verifyPassword() | Constant-time comparison prevents timing attacks, ensures password integrity |
| Blind Index Integrity | SensitiveDataProtector.createBlindIndex() | HMAC-based index ensures search queries match exact data |
| Digital Signatures | E2EEncryption + HMAC | HMAC-SHA384 in HKDF ensures derived keys haven't been altered |
| Audit Logging | SecurityAuditLogger | Immutable logs track all security events: login, encryption, access attempts |
| Version Control | ENC$v1$, $MLP$v1$ | Format versioning prevents replay attacks with old encryption schemes |
| AAD Support | E2EEncryption.encryptWithAAD() | Authenticated Associated Data binds metadata (user ID, timestamp) to ciphertext |
Integrity Implementation Details
1. Authentication Tags (AES-GCM)
// In CryptoCore.encryptAesGcm()
GCMParameterSpec gcmSpec = new GCMParameterSpec(GCM_TAG_LENGTH, iv); // 128-bit tag
cipher.init(Cipher.ENCRYPT_MODE, key, gcmSpec);
byte[] ciphertext = cipher.doFinal(plaintext); // Returns [ciphertext || 128-bit tag]
// Tag verified automatically during decryption
cipher.init(Cipher.DECRYPT_MODE, key, gcmSpec);
byte[] plaintext = cipher.doFinal(encrypted); // Throws exception if tag invalid
- What it protects: Detects any modification to encrypted data (even 1 bit change)
- When it fails: Throws
AEADBadTagExceptionif ciphertext or tag is altered - Performance: Hardware-accelerated, adds <1ms overhead
2. HMAC Signatures (Multi-Layer Vault)
// In MultiLayerPasswordVault.hashPassword()
// Layer 4: Sign the encrypted hash
SecretKey hmacKey = deriveHmacKey(salt);
byte[] hmacSignature = hmacSign(encryptedHash, hmacKey); // 64-byte signature
// In verifyPassword() - FAIL FAST approach
byte[] storedHmac = Arrays.copyOfRange(combined, combined.length - 64, combined.length);
byte[] computedHmac = hmacSign(encryptedHash, hmacKey);
if (!constantTimeEquals(computedHmac, storedHmac)) {
return false; // Stop immediately if tampered
}
- What it protects: Detects tampering BEFORE expensive decryption/hashing
- Fail-fast: Rejects invalid data in <1ms, saves ~200ms of computation
- Attack resistance: HMAC-SHA512 is quantum-resistant
3. Constant-Time Comparison
// In CryptoCore.constantTimeEquals()
private static boolean constantTimeEquals(byte[] a, byte[] b) {
if (a.length != b.length) return false;
int result = 0;
for (int i = 0; i < a.length; i++) {
result |= a[i] ^ b[i]; // XOR all bytes
}
return result == 0; // Single final comparison
}
- What it protects: Prevents timing attacks that measure comparison speed
- How it works: Always processes ALL bytes, regardless of where difference occurs
- Example attack prevented: Attacker can't guess password byte-by-byte by timing
4. Hash Chain Audit Logging
// In SecurityAuditLogger
private static String previousHash = "GENESIS_BLOCK_" + System.currentTimeMillis();
// Each log entry includes hash of previous entry (blockchain-style)
String computeHash(AuditEvent event) {
String data = event.timestamp + event.eventType + event.username +
event.action + previousHash; // Include previous hash
return SHA256(data);
}
// Log format: [timestamp][event][user][action][previous_hash][current_hash]
// Any tampering breaks the chain ā easily detected
- What it protects: Immutable audit trail, detects if logs are modified/deleted
- How detection works: If log N is altered, hash chain breaks at log N+1
- Real-world use: Same principle as blockchain
5. Database Audit Logging
// In LoginAuditLogger.logLoginEvent()
String sql = "INSERT INTO audit_logs (event_type, username, ip_address, " +
"action, details, timestamp) VALUES (?, ?, ?, ?, ?, ?)";
// Logs stored in database with:
// - Auto-incrementing ID (detects deleted rows)
// - Timestamp (immutable, server-side)
// - Event details (who, what, when, where)
- What it protects: User activity tracking, compliance requirements
- Dual logging: File-based (SecurityAuditLogger) + Database (LoginAuditLogger)
- Retention: Database logs kept indefinitely, files rotated daily
6. Intrusion Detection System
// In IntrusionDetection
// Tracks and blocks suspicious activity
private static final Map<String, ThreatScore> THREAT_SCORES = new ConcurrentHashMap<>();
void addScore(int points, String indicator) {
score.addAndGet(points);
indicators.add(String.format("[%s] %s (+%d)", Instant.now(), indicator, points));
if (score.get() >= THREAT_SCORE_BLOCK_THRESHOLD) {
blockEntity(identifier, "High threat score: " + score.get());
triggerAlert(SecurityAlert.CRITICAL, "Entity blocked due to threat score");
}
}
- What it protects: Detects brute force, rate limiting violations, SQL injection
- Threat scoring: Failed login (+10), SQL injection attempt (+50), XSS (+30)
- Auto-blocking: IP blocked for 1 hour when threat score ā„ 100
7. Format Versioning
// Password format: $MLP$v1$[salt]$[pepper_id]$[params]$[data]
// Data format: ENC$v1$[ciphertext]
// Version check prevents downgrade attacks
if (!storedHash.startsWith("$MLP$v1$")) {
// Reject older/unknown formats
return false;
}
- What it protects: Prevents replay attacks with old encryption schemes
- Migration path: Can upgrade users transparently (check
needsRehash()) - Future-proof: v2, v3 can coexist during transitions
8. Rate Limiting
// In IntrusionDetection.checkLoginAttempt()
RateLimitBucket bucket = IP_LOGIN_BUCKETS.computeIfAbsent(
ipAddress, k -> new RateLimitBucket(LOGIN_WINDOW, MAX_LOGIN_ATTEMPTS_PER_IP)
);
if (!bucket.tryAcquire()) {
// Exceeded 10 attempts in 15 minutes
blockIP(ipAddress, BLOCK_DURATION, "Exceeded login rate limit");
return false;
}
- What it protects: Prevents brute force attacks, credential stuffing
- Limits: 10 attempts per IP per 15 min, 5 per user per 15 min
- Sliding window: Dynamically tracks attempts, not simple counters
Availability (System Uptime & Accessibility)
| Implementation | Method/Class | How It Works |
|---|---|---|
| Searchable Encryption | SensitiveDataProtector.createBlindIndex() | Blind indexes allow fast searching without decrypting entire database |
| Format Detection | PasswordSecurityUtil.verifyPassword() | Auto-detects hash formats (MLP/Argon2id) for backward compatibility |
| Graceful Degradation | MultiLayerPasswordVault.verifyLegacyArgon2() | Supports old password formats, system remains operational during upgrades |
| Fast Verification | HMAC verification (Layer 4) | Fail-fast HMAC check rejects tampered data instantly without full decryption |
| Efficient Algorithms | AES-256-GCM | Hardware-accelerated AES-NI support, processes encryption at GB/s speeds |
| Session Management | SecureSessionManager | Persistent sessions prevent repeated authentication, reduces login bottlenecks |
| Parallel Processing | Argon2id parallelism=8 | Multi-threaded hashing uses all CPU cores efficiently |
| Connection Pooling | DatabaseConnection | Maintains connection pool, prevents database connection exhaustion |
CIA Summary Table
| Security Goal | Primary Protection | Secondary Protection | Detection Mechanism |
|---|---|---|---|
| Confidentiality | AES-256-GCM encryption | 5-layer password vault | PII detection, masking |
| Integrity | HMAC-SHA512 signatures | GCM authentication tags | Constant-time verification |
| Availability | Blind index searching | Format auto-detection | Security audit logs |
CIA in Action: Login Example
Login Request: username="john", password="secret123"
ā
āā CONFIDENTIALITY āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ⢠Password transmitted over encrypted channel
ā ⢠Never logged in plaintext (redactPII)
ā ⢠Database stores only encrypted hash
ā ⢠Memory wiped after verification
ā
āā INTEGRITY āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ⢠Retrieve stored hash: $MLP$v1$[salt]$...$[enc+hmac]
ā ⢠Verify HMAC first (fail-fast if tampered)
ā ⢠Decrypt hash using AES-256-GCM (verify auth tag)
ā ⢠Recompute: pepper ā Argon2id ā constant-time compare
ā ⢠Audit log: timestamp, IP, result (success/fail)
ā
āā AVAILABILITY āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
⢠Fast HMAC check rejects invalid data immediately
⢠Auto-detect format (supports legacy hashes)
⢠Parallel Argon2id processing (8 threads)
⢠Session token generated (avoid repeated auth)
⢠Connection pool ready for next request
⢠Total time: ~200-500ms per login
Document Version: 2.0
Last Updated: February 2, 2026
Security Level: Maximum Protection
Related Documents
MCP Server Specification: Grok Discussion Server
A standalone Model Context Protocol (MCP) server that enables intelligent discussions with Grok-4 AI, featuring context-aware conversations, baseline document generation, and response management.
C13.6: DAG Visualization & Workflow Security
> **Parent:** [C13 Monitoring, Logging & Anomaly Detection](C13-Monitoring-and-Logging)
Privacy Computing and Secure Execution Solutions - Comprehensive Research Report
**Date:** March 13, 2026