in src/main/java/com/amazonaws/encryptionsdk/kmssdkv2/KmsMasterKey.java [133:165]
public DataKey<KmsMasterKey> encryptDataKey(
final CryptoAlgorithm algorithm,
final Map<String, String> encryptionContext,
final DataKey<?> dataKey) {
final SecretKey key = dataKey.getKey();
if (!key.getFormat().equals("RAW")) {
throw new IllegalArgumentException("Only RAW encoded keys are supported");
}
try {
final EncryptResponse encryptResponse =
clientSupplier_
.get()
.encrypt(
EncryptRequest.builder()
.overrideConfiguration(API_NAME_INTERCEPTOR)
.keyId(id_)
.plaintext(SdkBytes.fromByteArray(key.getEncoded()))
.encryptionContext(encryptionContext)
.grantTokens(grantTokens_)
.build());
final ByteBuffer ciphertextBlobBuffer = encryptResponse.ciphertextBlob().asByteBuffer();
final byte[] edk = new byte[ciphertextBlobBuffer.remaining()];
ciphertextBlobBuffer.get(edk);
final String encryptResultKeyId = encryptResponse.keyId();
return new DataKey<>(
dataKey.getKey(), edk, encryptResultKeyId.getBytes(StandardCharsets.UTF_8), this);
} catch (final AwsServiceException asex) {
throw new AwsCryptoException(asex);
}
}