Skip to content

Commit

Permalink
fix(sdk): uses offset for ByteBuffer array offset (#209)
Browse files Browse the repository at this point in the history
ByteBuffer could have an array offset. We consider the length of the
ByteBuffer, but we do not consider the offset and default it to 0. This
PR fixes this problem by adding in the array offset when encrypting.
  • Loading branch information
imdominicreed authored Nov 7, 2024
1 parent 3325114 commit 0d6e761
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sdk/src/main/java/io/opentdf/platform/sdk/NanoTDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public int createNanoTDF(ByteBuffer data, OutputStream outputStream,
System.arraycopy(iv, 0, actualIV, kIvPadding, iv.length);
} while (Arrays.equals(actualIV, kEmptyIV)); // if match, we need to retry to prevent key + iv reuse with the policy

byte[] cipherData = gcm.encrypt(actualIV, authTagSize, data.array(), 0, dataSize);
byte[] cipherData = gcm.encrypt(actualIV, authTagSize, data.array(), data.arrayOffset(), dataSize);

// Write the length of the payload as int24
int cipherDataLengthWithoutPadding = cipherData.length - kIvPadding;
Expand Down

0 comments on commit 0d6e761

Please sign in to comment.