Created
June 7, 2017 05:15
-
-
Save gushernobindsme/7bab08062d0bb78b4d2eb3fcff8334b8 to your computer and use it in GitHub Desktop.
AWS Key Management Serviceのencrypt、decrypt実装サンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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