Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions vulnerable_weak_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ def hash_with_sha1(data):
return hashlib.sha1(data.encode()).hexdigest()

def encrypt_data_des(data, key):
cipher = DES.new(key, DES.MODE_ECB)
encrypted = cipher.encrypt(data)
return encrypted
from Crypto.Cipher import AES
cipher = AES.new(key, AES.MODE_GCM)
ciphertext, tag = cipher.encrypt_and_digest(data)
return cipher.nonce + tag + ciphertext

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function name misleadingly references DES despite using AES

Medium Severity

The function encrypt_data_des was changed to use AES.MODE_GCM internally, but the function name still says "des." This creates a misleading API contract — callers expect DES (8-byte key) but get AES (16/24/32-byte key), so any existing caller passing a DES-sized key will receive a runtime error. The return format also changed from raw ciphertext to nonce + tag + ciphertext with no update to the function name or signature to signal these breaking changes.

Fix in Cursor Fix in Web


def encrypt_with_arc2(plaintext, key):
cipher = ARC2.new(key, ARC2.MODE_ECB)
Expand Down
Loading