Skip to content

Commit 0d6e761

Browse files
fix(sdk): uses offset for ByteBuffer array offset (#209)
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.
1 parent 3325114 commit 0d6e761

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sdk/src/main/java/io/opentdf/platform/sdk/NanoTDF.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public int createNanoTDF(ByteBuffer data, OutputStream outputStream,
140140
System.arraycopy(iv, 0, actualIV, kIvPadding, iv.length);
141141
} while (Arrays.equals(actualIV, kEmptyIV)); // if match, we need to retry to prevent key + iv reuse with the policy
142142

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

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

0 commit comments

Comments
 (0)