Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions sdk/src/main/java/io/opentdf/platform/sdk/NanoTDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public int createNanoTDF(ByteBuffer data, OutputStream outputStream,
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hashOfSalt = digest.digest(MAGIC_NUMBER_AND_VERSION);
byte[] key = ECKeyPair.calculateHKDF(hashOfSalt, symmetricKey);
logger.debug("createNanoTDF key is - {}", Base64.getEncoder().encodeToString(key));

// Encrypt policy
PolicyObject policyObject = createPolicyObject(nanoTDFConfig.attributes);
Expand Down Expand Up @@ -135,9 +134,11 @@ public int createNanoTDF(ByteBuffer data, OutputStream outputStream,

// Encrypt the data
byte[] actualIV = new byte[kIvPadding + kNanoTDFIvSize];
byte[] iv = new byte[kNanoTDFIvSize];
SecureRandom.getInstanceStrong().nextBytes(iv);
System.arraycopy(iv, 0, actualIV, kIvPadding, iv.length);
do {
byte[] iv = new byte[kNanoTDFIvSize];
SecureRandom.getInstanceStrong().nextBytes(iv);
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);

Expand Down Expand Up @@ -173,7 +174,6 @@ public void readNanoTDF(ByteBuffer nanoTDF, OutputStream outputStream,
byte[] key = kas.unwrapNanoTDF(header.getECCMode().getEllipticCurveType(),
base64HeaderData,
kasUrl);
logger.debug("readNanoTDF key is {}", Base64.getEncoder().encodeToString(key));

byte[] payloadLengthBuf = new byte[4];
nanoTDF.get(payloadLengthBuf, 1, 3);
Expand Down