Lab 7: AES - Advanced Encryption Standard
Target: Mengenkripsi dan mendekripsi file dengan AES (standar enkripsi dunia)
Tools:openssl,python3+pycryptodome
Konsep
AES (Advanced Encryption Standard) adalah standar enkripsi global - digunakan oleh:
- Pemerintah AS (data rahasia)
- WhatsApp, Signal (end-to-end encryption)
- WiFi (WPA2), HTTPS (TLS), VPN
- Database, file encryption, disk encryption
Praktikum
cd ~ && mkdir crypto-lab7 && cd crypto-lab7
# 1. AES dengan OpenSSL
echo "=== AES-256-CBC dengan OpenSSL ==*"
echo "Data rahasia: Password Bank = 123456" > /tmp/secret.txt
# Enkripsi
openssl enc -aes-256-cbc -salt -in /tmp/secret.txt -out /tmp/secret.enc -pass pass:"RahasiaBanget" -pbkdf2
# Dekripsi
openssl enc -d -aes-256-cbc -in /tmp/secret.enc -out /tmp/secret_dec.txt -pass pass:"RahasiaBanget" -pbkdf2
echo "Original: $(cat /tmp/secret.txt)"
echo "Encrypted: $(xxd /tmp/secret.enc | head -3)"
echo "Decrypted: $(cat /tmp/secret_dec.txt)"
echo ""
# 2. AES dengan Python
python3 << 'PYEOF'
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
import os
# Data
data = b"Ini adalah data rahasia yang sangat penting!"
key = get_random_bytes(32) # AES-256
# ENKRIPSI (mode GCM - recommended)
cipher = AES.new(key, AES.MODE_GCM)
ciphertext, tag = cipher.encrypt_and_digest(data)
nonce = cipher.nonce
print(f"Key (hex): {key.hex()}")
print(f"Nonce (hex): {nonce.hex()}")
print(f"Ciphertext: {ciphertext.hex()}")
print(f"Tag (auth): {tag.hex()}")
# DEKRIPSI
cipher_dec = AES.new(key, AES.MODE_GCM, nonce=nonce)
plaintext = cipher_dec.decrypt_and_verify(ciphertext, tag)
print(f"Decrypted: {plaintext.decode()}")
print()
# 3. AES modes comparison
print("=== AES Modes ==*")
print("ECB: Sama plaintext → sama ciphertext ❌ (vulnerable)")
print("CBC: Setiap blok tergantung blok sebelumnya ✅")
print("GCM: CBC + authentication tag ✅✅ (recommended!)")
print("CTR: Stream mode - bisa parallel processing")
PYEOF
️ Analisis
| Komponen AES | Ukuran | Keterangan |
|---|---|---|
| Key | 128/192/256 bit | 256 = militer grade |
| Block size | 128 bit | Selalu 128 bit |
| Mode | GCM | Recommended (auth + encrypt) |
| Rounds | 10/12/14 | Tergantung key size |
Refleksi: AES adalah standar emas kriptografi simetris. Selalu gunakan mode GCM (authenticated encryption) yang memberikan kerahasiaan + integritas. Jangan gunakan ECB - pola plaintext masih terlihat.
Generated by @farishhz Agent Pentest Pipeline - TDCTF Security Academy