AES in ECB mode protects the vault
Green Agent's note
ECB encrypts identical blocks to identical output, so patterns in the data survive. GCM uses a fresh IV for every message and authenticates the result, so tampering is caught too. open() now reads the 12-byte IV from the front of the ciphertext.
fun seal(data: ByteArray): ByteArray {
val c = Cipher.getInstance("AES/ECB/PKCS5Padding")
c.init(Cipher.ENCRYPT_MODE, key)
return c.doFinal(data)
}
Same input, same output.
fun seal(data: ByteArray): ByteArray {
val c = Cipher.getInstance("AES/GCM/NoPadding")
c.init(Cipher.ENCRYPT_MODE, key)
return c.iv + c.doFinal(data)
}
A new IV every time.