Created
November 29, 2016 09:14
-
-
Save mardymark/d9b38a6eeb431a5a94d53e89a6c72048 to your computer and use it in GitHub Desktop.
golang-encrypt-using-kms
This file contains hidden or 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
| func encryptSecret(name string, value string) (string, error) { | |
| kmsKeyARN := "arn:aws:kms:us-east-1:012345678910:key/0000000-0000-0000-0000-000000000000" | |
| kmsClient := kms.New(session.New(&aws.Config{ | |
| Region: aws.String("us-east-1"), | |
| })) | |
| params := &kms.EncryptInput{ | |
| KeyId: aws.String(kmsKeyARN), | |
| Plaintext: []byte(value), | |
| } | |
| resp, err := kmsClient.Encrypt(params) | |
| if err != nil { | |
| return "", err | |
| } | |
| err = ioutil.WriteFile(name, resp.CiphertextBlob, 0644) | |
| if err != nil { | |
| return "", err | |
| } | |
| return name, nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment