Example usage for com.amazonaws.services.kms.model EncryptRequest addEncryptionContextEntry

List of usage examples for com.amazonaws.services.kms.model EncryptRequest addEncryptionContextEntry

Introduction

In this page you can find the example usage for com.amazonaws.services.kms.model EncryptRequest addEncryptionContextEntry.

Prototype

public EncryptRequest addEncryptionContextEntry(String key, String value) 

Source Link

Usage

From source file:com.google.crypto.tink.integration.awskms.AwsKmsAead.java

License:Apache License

@Override
public byte[] encrypt(final byte[] plaintext, final byte[] associatedData) throws GeneralSecurityException {
    try {//from  w w w.  j  a  v a2  s.  c  om
        EncryptRequest req = new EncryptRequest().withKeyId(keyArn).withPlaintext(ByteBuffer.wrap(plaintext));
        if (associatedData != null && associatedData.length != 0) {
            req = req.addEncryptionContextEntry("associatedData", BinaryUtils.toHex(associatedData));
        }
        return kmsClient.encrypt(req).getCiphertextBlob().array();
    } catch (AmazonServiceException e) {
        throw new GeneralSecurityException("encryption failed", e);
    }
}