Code RoomAES field encryption
HardPrep Room Coding #2069

AES field encryption

Code reviewSecuritySenior–Staff~22 min

Review this Java field-encryption helper used to store PII columns.

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 22 min
Mark a line and say what kind of problem it is.0 findings
1public class FieldCrypto {
2 private final SecretKey key; // AES-256, loaded from KMS
3 
4 public FieldCrypto(SecretKey key) {
5 this.key = key;
6 }
7 
8 public byte[] encrypt(byte[] plaintext) throws Exception {
9 Cipher c = Cipher.getInstance("AES");
10 c.init(Cipher.ENCRYPT_MODE, key);
11 return c.doFinal(plaintext);
12 }
13 
14 public String encryptField(String value) throws Exception {
15 return Base64.getEncoder().encodeToString(encrypt(value.getBytes(StandardCharsets.UTF_8)));
16 }
17}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.