Skip to content

Instantly share code, notes, and snippets.

@gushernobindsme
Created June 7, 2017 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gushernobindsme/7bab08062d0bb78b4d2eb3fcff8334b8 to your computer and use it in GitHub Desktop.
Save gushernobindsme/7bab08062d0bb78b4d2eb3fcff8334b8 to your computer and use it in GitHub Desktop.
AWS Key Management Serviceのencrypt、decrypt実装サンプル
private String encrypt(){
String keyId = "arn:aws:kms:...";
ByteBuffer plaintext = ByteBuffer.wrap("plainText".getBytes());
EncryptRequest req = new EncryptRequest()
.withKeyId(keyId)
.withPlaintext(plaintext);
ByteBuffer ciphertext = AWSKMSClient.encrypt(req).getCiphertextBlob();
return Base64.getEncoder().encodeToString(ciphertext.array());
}
private String decrypt(){
DecryptRequest req = new DecryptRequest()
.withCiphertextBlob(ByteBuffer.wrap(Base64.getDecoder()
.decode("cipherText".getBytes())));
ByteBuffer plaintext = AWSKMSClient.decrypt(req).getPlaintext();
return new String(plaintext.array());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment