Can an encryption key be inferred by knowing the plaintext and the corresponding ciphertext? Thinking about validation methods for guaranteeing a proper key is used. Will keeping a dummy plaintext value and its corresponding ciphertext in plaintext code expose any risk?
Good thinking!
The good news is that, when you use authenticated encryption, there's no need to keep such &quot;dummy&quot; plaintext-ciphertext pair.
In a typical authenticated encryption, a tag is computed based on the key, the plaintext, and possibly additional data (e.g. AAD, Initialization Vector), so that upon decryption, the tag is verified for correctness. Typically, the tag is 128-bit as is the case with GCM-AES and ChaCha20-Poly1305.
Successful decryption of an authenticated ciphertext indicates that if the correct key had been used then the ciphertext along with other inputs to the encryption algorithm are correct and had not be modified by any man-in-the-middle.