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

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

Introduction

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

Prototype


public void setKeyId(String keyId) 

Source Link

Document

A unique identifier for the customer master key (CMK).

Usage

From source file:org.apache.coheigea.cxf.kms.asymmetric.KMSPasswordEncryptor.java

License:Apache License

@Override
public String encrypt(String password) {
    final AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);

    AWSKMSClient kms = new AWSKMSClient(creds);
    kms.setEndpoint(endpoint);//from   www. ja  v  a  2s .  co m

    ByteBuffer plaintext = ByteBuffer.wrap(password.getBytes());

    EncryptRequest req = new EncryptRequest().withPlaintext(plaintext);
    req.setKeyId(masterKeyId);
    ByteBuffer encryptedKey = kms.encrypt(req).getCiphertextBlob();

    byte[] key = new byte[encryptedKey.remaining()];
    encryptedKey.get(key);

    return Base64.encode(key);
}