in c3r-sdk-core/src/main/java/com/amazonaws/c3r/internal/InitializationVector.java [50:75]
public static InitializationVector deriveIv(final String label, final Nonce nonce) {
if (label == null || label.isBlank()) {
throw new C3rIllegalArgumentException("A column label must be provided when generating an IV, but was null or empty.");
}
if (nonce == null) {
throw new C3rIllegalArgumentException("A nonce must be provided when generating an IV, but was null.");
}
final byte[] labelBytes = label.getBytes(StandardCharsets.UTF_8);
final byte[] nonceBytes = nonce.getBytes();
final byte[] buffer = ByteBuffer.allocate(labelBytes.length + nonceBytes.length)
.put(labelBytes)
.put(nonceBytes)
.array();
final MessageDigest messageDigest;
try {
messageDigest = MessageDigest.getInstance(KeyUtil.HASH_ALG);
} catch (NoSuchAlgorithmException e) {
throw new C3rRuntimeException("Requested algorithm `" + KeyUtil.HASH_ALG + "` is not available!", e);
}
final byte[] hash = messageDigest.digest(buffer);
final byte[] iv = new byte[InitializationVector.IV_BYTE_LENGTH];
if (hash != null) {
ByteBuffer.wrap(hash).get(iv);
}
return new InitializationVector(iv);
}