// 1. Replace example key with encryption string
var key = "v9y$B&E(H+MbQeThWmZq4t7w!z%C*F-J"
// 2. Replace strings "username", "password", "dbName"with credentials
var stringsToBeEncrypted = []string{
// 3. Run program to see encrypted credentials in console
for i := range stringsToBeEncrypted {
encrypted, err := EncryptString(stringsToBeEncrypted[i])
fmt.Printf("%s => %s\n", stringsToBeEncrypted[i],encrypted)
func EncryptString(str string) (encrypted string,err error) {
block, err := aes.NewCipher(keyBytes)
aesGCM, err := cipher.NewGCM(block)
nonce := make([]byte, aesGCM.NonceSize())
if _, err = io.ReadFull(rand.Reader, nonce); err!= nil {
cipherBytes := aesGCM.Seal(nonce, nonce, strBytes,nil)
return fmt.Sprintf("%x", cipherBytes), err