Skip to content

Commit

Permalink
Always update associated data via byte array
Browse files Browse the repository at this point in the history
  • Loading branch information
jchambers committed Mar 3, 2024
1 parent 68995f0 commit c9ae0ea
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public int encrypt(final Key key,
initCipher(cipher, Cipher.ENCRYPT_MODE, key, nonce);

if (associatedData != null) {
cipher.updateAAD(associatedData);
final byte[] adBytes = new byte[associatedData.remaining()];
associatedData.get(adBytes);

cipher.updateAAD(adBytes);
}

return finishEncryption(() -> cipher.doFinal(plaintext, ciphertext));
Expand Down Expand Up @@ -75,7 +78,10 @@ public int decrypt(final Key key,
initCipher(cipher, Cipher.DECRYPT_MODE, key, nonce);

if (associatedData != null) {
cipher.updateAAD(associatedData);
final byte[] adBytes = new byte[associatedData.remaining()];
associatedData.get(adBytes);

cipher.updateAAD(adBytes);
}

return finishDecryption(() -> cipher.doFinal(ciphertext, plaintext));
Expand Down

0 comments on commit c9ae0ea

Please sign in to comment.