Description
DES has a 56-bit effective key, and ECB mode reveals repeated patterns in the data. Padding fixes neither problem.
Potential impact
Sensitive data or credentials can be exposed. Without an integrity check, the application can also accept altered data.
Remediation
Use authenticated encryption such as AES-GCM from a vetted library. Generate and store keys securely and use a fresh nonce for every encryption with the same key. Account for existing ciphertext formats and keys when planning migration.
Examples
The PyCryptodome example generates a new key in memory. Keep production keys in a separate protected store so that stored data can be decrypted later.
Before
# Unsafe DES encryption
from Crypto.Cipher import DES
from Crypto.Util.Padding import pad
key = b'8bytekey' # 56-bit DES key
cipher = DES.new(key, DES.MODE_ECB)
plaintext = b'This is a secret message.'
ciphertext = cipher.encrypt(pad(plaintext, DES.block_size))
After
# Authenticated AES encryption
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
key = get_random_bytes(32) # 256-bit AES key
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)
Explanation
Keep or send the ciphertext, nonce and tag together. Use the plaintext only after decrypt_and_verify successfully verifies the tag.