설명
DES의 유효 키 길이는 56비트이고 ECB 모드는 반복되는 데이터 패턴을 드러냅니다. 패딩을 추가해도 두 문제는 해결되지 않습니다.
잠재적 영향
민감한 데이터나 인증 정보가 노출될 수 있습니다. 무결성을 검증하지 않으면 애플리케이션이 변조된 데이터도 처리할 수 있습니다.
해결 방법
검증된 라이브러리의 AES-GCM 같은 인증된 암호화를 사용하세요. 키를 안전하게 생성·보관하고 같은 키에서 nonce를 재사용하지 마세요. 기존 데이터를 이전하기 전에 암호문 형식과 복호화에 필요한 키를 확인하세요.
예시
PyCryptodome 예시는 매번 새 키를 생성합니다. 저장한 데이터를 나중에 복호화하려면 키를 별도의 보호된 저장소에서 관리하세요.
변경 전
python
# Unsafe DES encryption
from Crypto.Cipher import DES
from Crypto.Util.Padding import pad
key = b'8bytekey' # 56비트 DES 키
cipher = DES.new(key, DES.MODE_ECB)
plaintext = b'This is a secret message.'
ciphertext = cipher.encrypt(pad(plaintext, DES.block_size))
변경 후
python
# Authenticated AES encryption
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
key = get_random_bytes(32) # 256비트 AES 키
cipher = AES.new(key, AES.MODE_GCM)
plaintext = b'This is a secret message.'
ciphertext, tag = cipher.encrypt_and_digest(plaintext)
nonce = cipher.nonce
receiver = AES.new(key, AES.MODE_GCM, nonce=nonce)
recovered = receiver.decrypt_and_verify(ciphertext, tag)
설명
암호문과 nonce, tag를 함께 보관하거나 전송하세요. decrypt_and_verify가 태그를 검증한 뒤에만 복호화한 데이터를 사용하세요.