- name
- cryptography-policy
- description
- Cryptographic controls implementation: TLS 1.3, AES-256-GCM, bcrypt, RSA-4096, key management per NIST FIPS 140-2 and ISO 27001 A.8.24
# Cryptography Policy Skill
## Purpose
This skill establishes cryptographic standards and implementation patterns for the CIA platform, ensuring proper encryption of data at rest, in transit, and in processing. It demonstrates professional cryptographic practices aligned with NIST FIPS 140-2, ISO 27001 A.8.24, and Hack23 ISMS Cryptography Policy.
## When to Use This Skill
Apply this skill when:
- ✅ Implementing encryption for sensitive data storage
- ✅ Configuring TLS/SSL for network communication
- ✅ Managing cryptographic keys and certificates
- ✅ Implementing password hashing and authentication
- ✅ Designing secure API authentication mechanisms
- ✅ Configuring AWS encryption services (KMS, S3, RDS)
- ✅ Implementing digital signatures or message authentication
- ✅ Conducting cryptographic compliance audits
Do NOT use for:
- ❌ Encoding/decoding (Base64, URL encoding - not encryption)
- ❌ Compression (gzip, zip - not security)
- ❌ Obfuscation (code minification - not cryptography)
## Decision Tree
```mermaid
%%{
init: {
'theme': 'base',
'themeVariables': {
'primaryColor': '#1565C0',
'primaryTextColor': '#fff',
'lineColor': '#1565C0',
'secondaryColor': '#7B1FA2',
'tertiaryColor': '#4CAF50'
}
}
}%%
flowchart TD
START["🔒 Cryptography Need"] --> TYPE{"📊 Data State?"}
TYPE -->|At Rest| REST["💾 Data at Rest<br/>Storage Encryption"]
TYPE -->|In Transit| TRANSIT["🌐 Data in Transit<br/>TLS/HTTPS"]
TYPE -->|In Use| USE["🔐 Data in Use<br/>Application Encryption"]
REST --> CLASS{"🏷️ Data Classification?"}
TRANSIT --> PROTOCOL{"📡 Protocol?"}
USE --> ALGO{"🔑 Algorithm Type?"}
CLASS -->|Extreme/High| AES256["🔐 AES-256-GCM<br/>Customer Managed Keys"]
CLASS -->|Standard/Low| AES128["🔐 AES-256<br/>Service Managed Keys"]
PROTOCOL -->|Web/API| HTTPS["🌐 HTTPS/TLS 1.3<br/>Strong Ciphers"]
PROTOCOL -->|Database| DBSSL["🗄️ Database SSL/TLS<br/>PostgreSQL SSL"]
PROTOCOL -->|Email| SMTPTLS["📧 SMTP + TLS<br/>S/MIME Optional"]
ALGO -->|Symmetric| SYM["🔐 AES-256-GCM<br/>Authenticated Encryption"]
ALGO -->|Asymmetric| ASYM["🔑 RSA-4096 or Ed25519<br/>Public Key Crypto"]
ALGO -->|Hashing| HASH[#️⃣ SHA-256 or bcrypt<br/>Secure Hashing]
AES256 --> KMS["🔑 AWS KMS<br/>Key Management"]
AES128 --> KMS
SYM --> KMS
ASYM --> KEYSTORE["🏦 Key Storage<br/>HSM or Secrets Manager"]
HASH --> IMPL["✅ Implementation"]
HTTPS --> TLS["✅ TLS Configuration"]
DBSSL --> TLS
SMTPTLS --> TLS
KMS --> ROTATION["🔄 Key Rotation<br/>Annual Minimum"]
KEYSTORE --> ROTATION
TLS --> CERT["📜 Certificate Management<br/>90-day Renewal"]
ROTATION --> AUDIT["📊 Audit Logging<br/>All Key Operations"]
CERT --> AUDIT
IMPL --> AUDIT
style START fill:#1565C0,color:#fff
style AES256 fill:#7B1FA2,color:#fff
style HTTPS fill:#4CAF50,color:#fff
style KMS fill:#FF9800,color:#fff
style AUDIT fill:#4CAF50,color:#fff
```
## Approved Cryptographic Algorithms
### Symmetric Encryption
**✅ APPROVED: AES (Advanced Encryption Standard)**
```yaml
Algorithm: AES
Key_Sizes:
- 256-bit (Preferred)
- 192-bit (Acceptable)
- 128-bit (Legacy support only)
Modes:
Recommended:
- GCM (Galois/Counter Mode): Authenticated encryption
- CCM (Counter with CBC-MAC): Authenticated encryption
Acceptable_with_Caution:
- CBC (Cipher Block Chaining): Requires HMAC for authentication
- CTR (Counter Mode): Requires HMAC for authentication
PROHIBITED:
- ECB (Electronic Codebook): Insecure, deterministic
- OFB, CFB: Use GCM or CCM instead
Use_Cases:
- Database encryption (RDS, PostgreSQL)
- File encryption (S3, EBS volumes)
- Application-level encryption
- Session data encryption
```
**Java Implementation:**
```java
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.SecureRandom;
/**
* AES-256-GCM encryption implementation
* Compliant with NIST SP 800-38D
*/
public class SecureEncryption {
private static final String ALGORITHM = "AES";
private static final String TRANSFORMATION = "AES/GCM/NoPadding";
private static final int KEY_SIZE = 256;
private static final int GCM_IV_LENGTH = 12; // 96 bits
private static final int GCM_TAG_LENGTH = 128; // 128 bits
/**
* Generate a new AES-256 encryption key
*/
public static SecretKey generateKey() throws Exception {
KeyGenerator keyGenerator = KeyGenerator.getInstance(ALGORITHM);
keyGenerator.init(KEY_SIZE, new SecureRandom());
return keyGenerator.generateKey();
}
/**
* Encrypt data using AES-256-GCM
*
* @param plaintext Data to encrypt
* @param key AES-256 secret key
* @return Encrypted data (IV + ciphertext + tag)
*/
public static byte[] encrypt(byte[] plaintext, SecretKey key) throws Exception {
// Generate random IV
byte[] iv = new byte[GCM_IV_LENGTH];
new SecureRandom().nextBytes(iv);
// Initialize cipher
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH, iv);
cipher.init(Cipher.ENCRYPT_MODE, key, spec);
// Encrypt
byte[] ciphertext = cipher.doFinal(plaintext);
// Combine IV + ciphertext for storage
byte[] encrypted = new byte[iv.length + ciphertext.length];
System.arraycopy(iv, 0, encrypted, 0, iv.length);
System.arraycopy(ciphertext, 0, encrypted, iv.length, ciphertext.length);
return encrypted;
}
/**
* Decrypt data using AES-256-GCM
*
* @param encrypted Encrypted data (IV + ciphertext + tag)
* @param key AES-256 secret key
* @return Decrypted plaintext
*/
public static byte[] decrypt(byte[] encrypted, SecretKey key) throws Exception {
// Extract IV
byte[] iv = new byte[GCM_IV_LENGTH];
System.arraycopy(encrypted, 0, iv, 0, iv.length);
// Extract ciphertext
byte[] ciphertext = new byte[encrypted.length - GCM_IV_LENGTH];
System.arraycopy(encrypted, GCM_IV_LENGTH, ciphertext, 0, ciphertext.length);
// Initialize cipher
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH, iv);
cipher.init(Cipher.DECRYPT_MODE, key, spec);
// Decrypt and verify authentication tag
return cipher.doFinal(ciphertext);
}
}
```
**❌ PROHIBITED: DES, 3DES, RC4**
```yaml
Deprecated_Algorithms:
DES:
Reason: 56-bit key length insufficient
Replacement: AES-256
Deadline: Immediate removal required
3DES:
Reason: Block size vulnerability (Sweet32)
Replacement: AES-256
Deadline: Migrate by end of 2025
RC4:
Reason: Multiple cryptographic weaknesses
Replacement: AES-GCM or ChaCha20-Poly1305
Deadline: Immediate removal required
```
### Asymmetric Encryption
**✅ APPROVED: RSA**
```yaml
Algorithm: RSA
Key_Sizes:
- 4096-bit (Preferred for long-term keys)
- 3072-bit (Acceptable)
- 2048-bit (Minimum, legacy support only)
Padding_Schemes:
Encryption:
- OAEP (Optimal Asymmetric Encryption Padding) with SHA-256
Signature:
- PSS (Probabilistic Signature Scheme) with SHA-256
PROHIBITED_Padding:
- PKCS#1 v1.5: Vulnerable to padding oracle attacks
Use_Cases:
- SSH keys (prefer Ed25519)
- TLS certificates (prefer ECDSA)
- Data encryption for small payloads
- Digital signatures
```
**Java Implementation:**
```java
import java.security.*;
import javax.crypto.Cipher;
import java.security.spec.RSAKeyGenParameterSpec;
/**
* RSA-4096 encryption and signature implementation
* Compliant with NIST SP 800-56B
*/
public class RSASecureEncryption {
private static final int KEY_SIZE = 4096;
private static final String ALGORITHM = "RSA";
private static final String TRANSFORMATION = "RSA/ECB/OAEPWithSHA-256AndMGF1Padding";
private static final String SIGNATURE_ALGORITHM = "SHA256withRSA/PSS";
/**
* Generate RSA-4096 key pair
*/
public static KeyPair generateKeyPair() throws Exception {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM);
keyGen.initialize(KEY_SIZE, new SecureRandom());
return keyGen.generateKeyPair();
}
/**
* Encrypt data using RSA-OAEP
* Note: RSA should only encrypt small data (e.g., symmetric keys)
* For large data, use hybrid encryption (RSA + AES)
*/
public static byte[] encrypt(byte[] plaintext, PublicKey publicKey) throws Exception {
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
return cipher.doFinal(plaintext);
}
/**
* Decrypt data using RSA-OAEP
*/
public static byte[] decrypt(byte[] ciphertext, PrivateKey privateKey) throws Exception {
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(Cipher.DECRYPT_MODE, privateKey);
return cipher.doFinal(ciphertext);
}
/**
* Sign data using RSA-PSS
*/
public static byte[] sign(byte[] data, PrivateKey privateKey) throws Exception {
Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
signature.initSign(privateKey);
signature.update(data);
return signature.sign();
}
/**
* Verify signature using RSA-PSS
*/
public static boolean verify(byte[] data, byte[] signatureBytes, PublicKey publicKey)
throws Exception {
Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
signature.initVerify(publicKey);
signature.update(data);
return signature.verify(signatureBytes);
}
}
```
**✅ APPROVED: Elliptic Curve Cryptography (ECC)**
```yaml
Algorithm: ECDSA / ECDH
Curves:
Preferred:
- Ed25519 (EdDSA signatures)
- X25519 (ECDH key exchange)
- P-384 (NIST curve for FIPS compliance)
Acceptable:
- P-256 (secp256r1, prime256v1)
PROHIBITED:
- P-192: Insufficient security margin
- Custom curves: Avoid unless peer-reviewed
Use_Cases:
- SSH keys (Ed25519 preferred)
- TLS certificates (ECDSA preferred over RSA)
- JWT signatures
- Cryptocurrency/blockchain applications
```
**SSH Key Generation Example:**
```bash
# Generate Ed25519 SSH key (RECOMMENDED)
ssh-keygen -t ed25519 -C "user@cia.hack23.com" -f ~/.ssh/id_ed25519
# Generate ECDSA SSH key (alternative)
ssh-keygen -t ecdsa -b 384 -C "user@cia.hack23.com" -f ~/.ssh/id_ecdsa
# Generate RSA SSH key (legacy compatibility)
ssh-keygen -t rsa -b 4096 -C "user@cia.hack23.com" -f ~/.ssh/id_rsa
# Verify SSH key fingerprint
ssh-keygen -lf ~/.ssh/id_ed25519.pub
```
### Cryptographic Hashing
**✅ APPROVED: SHA-2 Family**
```yaml
Algorithms:
SHA-256:
Output: 256 bits
Use: General purpose, integrity verification
Status: Approved
SHA-384:
Output: 384 bits
Use: Higher security margin required
Status: Approved
SHA-512:
Output: 512 bits
Use: Long-term security, high-security applications
Status: Approved
Use_Cases:
- File integrity verification
- Digital signatures
- Certificate fingerprints
- HMAC authentication
- Git commit hashing
```
**Java Implementation:**
```java
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.xml.bind.DatatypeConverter;
/**
* Secure hashing implementation
*/
public class SecureHashing {
/**
* Calculate SHA-256 hash
*/
public static byte[] sha256(byte[] data) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
return digest.digest(data);
}
/**
* Calculate SHA-256 hash as hex string
*/
public static String sha256Hex(byte[] data) throws NoSuchAlgorithmException {
byte[] hash = sha256(data);
return DatatypeConverter.printHexBinary(hash).toLowerCase();
}
/**
* Calculate SHA-512 hash
*/
public static byte[] sha512(byte[] data) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-512");
return digest.digest(data);
}
}
```
**❌ PROHIBITED: MD5, SHA-1**
```yaml
Deprecated_Algorithms:
MD5:
Reason: Collision attacks practical since 2004
Replacement: SHA-256
Deadline: Immediate removal required
Exception: Git commit hashes (backward compatibility)
SHA-1:
Reason: Collision attacks demonstrated (SHAttered)
Replacement: SHA-256
Deadline: Immediate removal required
Exception: Git commit hashes (Git working on SHA-256 migration)
```
### Password Hashing
**✅ APPROVED: bcrypt, Argon2, PBKDF2**
```yaml
Algorithms:
bcrypt:
Cost_Factor: 12-15 (balance security and performance)
Use: Password storage, user authentication
Status: Preferred
Argon2id:
Memory: 64 MB
Iterations: 3
Parallelism: 4
Use: High-security password storage
Status: Preferred (if available)
PBKDF2-SHA256:
Iterations: 600,000+ (OWASP 2023 recommendation)
Salt: 128 bits minimum
Use: Password storage (fallback if bcrypt unavailable)
Status: Acceptable
Key_Principles:
- Always use unique random salt per password
- Store salt alongside hash
- Never use fast hashes (MD5, SHA-256) for passwords
- Cost factor should take ~100ms on production hardware
```
**Java Implementation (bcrypt):**
```java
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
/**
* Secure password hashing using bcrypt
* Spring Security provides robust implementation
*/
public class PasswordSecurity {
// Cost factor 12 = 2^12 iterations
private static final int COST_FACTOR = 12;
private static final BCryptPasswordEncoder encoder =
new BCryptPasswordEncoder(COST_FACTOR);
/**
* Hash password using bcrypt
Auf GitHub ansehen