use of com.amazonaws.services.kms.model.EncryptRequest in project spring-cloud-config-aws-kms by zalando.
the class KmsTextEncryptorTest method setUp.
@Before
public void setUp() throws Exception {
mockKms = mock(AWSKMS.class);
textEncryptor = new KmsTextEncryptor(mockKms, KMS_KEY_ID);
expectedEncryptRequest = new EncryptRequest();
expectedEncryptRequest.setKeyId(KMS_KEY_ID);
expectedEncryptRequest.setPlaintext(wrap(PLAINTEXT.getBytes()));
encryptResult = new EncryptResult();
encryptResult.setCiphertextBlob(wrap(CIPHER_TEXT.getBytes()));
when(mockKms.encrypt(any(EncryptRequest.class))).thenReturn(encryptResult);
expectedDecryptRequest = new DecryptRequest();
expectedDecryptRequest.setCiphertextBlob(wrap(CIPHER_TEXT.getBytes()));
decryptResult = new DecryptResult();
decryptResult.setPlaintext(wrap(PLAINTEXT.getBytes()));
when(mockKms.decrypt(any(DecryptRequest.class))).thenReturn(decryptResult);
}
use of com.amazonaws.services.kms.model.EncryptRequest in project testcases by coheigea.
the class KMSPasswordEncryptor method encrypt.
@Override
public String encrypt(String password) {
final AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
AWSKMSClient kms = new AWSKMSClient(creds);
kms.setEndpoint(endpoint);
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);
}
use of com.amazonaws.services.kms.model.EncryptRequest in project spring-cloud-config-aws-kms by zalando.
the class KmsTextEncryptor method encrypt.
@Override
public String encrypt(final String text) {
Assert.hasText(kmsKeyId, "kmsKeyId must not be blank");
if (text == null || text.isEmpty()) {
return EMPTY_STRING;
} else {
final EncryptRequest encryptRequest = //
new EncryptRequest().withKeyId(kmsKeyId).withPlaintext(ByteBuffer.wrap(text.getBytes()));
final ByteBuffer encryptedBytes = kms.encrypt(encryptRequest).getCiphertextBlob();
return extractString(ByteBuffer.wrap(Base64.encode(encryptedBytes.array())));
}
}
use of com.amazonaws.services.kms.model.EncryptRequest in project aws-doc-sdk-examples by awsdocs.
the class EncryptDataKey method main.
public static void main(String[] args) {
AWSKMS kmsClient = AWSKMSClientBuilder.standard().build();
// Encrypt a data key
//
// Replace the following fictitious CMK ARN with a valid CMK ID or ARN
String keyId = "1234abcd-12ab-34cd-56ef-1234567890ab";
ByteBuffer plaintext = ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
EncryptRequest req = new EncryptRequest().withKeyId(keyId).withPlaintext(plaintext);
ByteBuffer ciphertext = kmsClient.encrypt(req).getCiphertextBlob();
}
Aggregations