Skip to content

Instantly share code, notes, and snippets.

@mardymark
Created November 29, 2016 09:37
Show Gist options
  • Select an option

  • Save mardymark/7591ea854fc1b8cce8ac132ff642a006 to your computer and use it in GitHub Desktop.

Select an option

Save mardymark/7591ea854fc1b8cce8ac132ff642a006 to your computer and use it in GitHub Desktop.
golang-decrypt-using-kms
func decryptSecretFile(secretFile string) (string, error) {
secretBytes, err := ioutil.ReadFile(secretFile)
if err != nil {
return "", err
}
kmsClient := kms.New(session.New(&aws.Config{
Region: aws.String("us-east-1"),
}))
params := &kms.DecryptInput{
CiphertextBlob: secretBytes,
}
resp, err := kmsClient.Decrypt(params)
if err != nil {
return "", err
}
err = os.Remove(secretFile)
if err != nil {
return "", err
}
return string(resp.Plaintext), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment