AES encryption uses ECB mode
Review this Python encryption helper.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 25 min
Mark a line and say what kind of problem it is.0 findings
1from Crypto.Cipher import AES
2from Crypto.Util.Padding import pad, unpad
3
4def encrypt_blob(key: bytes, plaintext: bytes) -> bytes:
5 # key is 32 bytes, validated by the caller
6 cipher = AES.new(key, AES.MODE_ECB)
7 return cipher.encrypt(pad(plaintext, AES.block_size))
8
9def decrypt_blob(key: bytes, ciphertext: bytes) -> bytes:
10 cipher = AES.new(key, AES.MODE_ECB)
11 return unpad(cipher.decrypt(ciphertext), AES.block_size)
12
13# Used to encrypt user profile records before storing in S3
14blob = encrypt_blob(master_key, profile.SerializeToString())
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.