Skip to content

Commit

Permalink
don't unnecessarily copy memory
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamVe committed Nov 21, 2023
1 parent bc27e72 commit 5525a7a
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ public byte[] decrypt(byte[] key, byte[] ciphertext) {
aesKey = Arrays.copyOfRange(key, 32, key.length);
byte[] iv = Arrays.copyOf(ciphertext, 16);
byte[] ct = Arrays.copyOfRange(ciphertext, 16, ciphertext.length);
byte[] plaintext = getCipher(Cipher.DECRYPT_MODE, aesKey, iv).doFinal(ct);
return Arrays.copyOf(plaintext, plaintext.length);
return getCipher(Cipher.DECRYPT_MODE, aesKey, iv).doFinal(ct);
} catch (BadPaddingException | IllegalBlockSizeException e) {
throw new IllegalStateException(e);
} finally {
Expand All @@ -139,8 +138,7 @@ public byte[] authenticate(byte[] key, byte[] message) {
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new RuntimeException(e);
}
byte[] result = mac.doFinal(message);
return Arrays.copyOf(result, result.length);
return mac.doFinal(message);
}

private Cipher getCipher(int mode, byte[] secret, byte[] iv) {
Expand Down

0 comments on commit 5525a7a

Please sign in to comment.