Last active
June 19, 2017 13:34
-
-
Save ElisaBaum/c4980fdade93c4310401096025cb9bab to your computer and use it in GitHub Desktop.
Util to decrypt AWS KMS encrypted keys
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
import java.nio.ByteBuffer | |
import java.nio.charset.Charset | |
import com.amazonaws.services.kms.AWSKMSClientBuilder | |
import com.amazonaws.services.kms.model.DecryptRequest | |
import com.amazonaws.util.Base64 | |
object KMSDecryptionUtil { | |
private lazy val kmsClient = AWSKMSClientBuilder.defaultClient() | |
def decrypt(encryptedValue: String): String = { | |
val encrypted = Base64.decode(encryptedValue) | |
val decryptedResult = kmsClient | |
.decrypt(new DecryptRequest().withCiphertextBlob(ByteBuffer.wrap(encrypted))) | |
.getPlaintext | |
new String(decryptedResult.array(), Charset.forName("UTF-8")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment