package aes import ( // Standard "crypto/aes" "crypto/cipher" "crypto/rand" "encoding/base64" ) // Encrypt func (Algorithm) Encrypt(data []byte, key []byte) (string, error) { // Block block, err := aes.NewCipher(key) // Handle Error if err != nil { return "", err } // GCM gcm, err := cipher.NewGCM(block) // Handle Error if err != nil { return "", err } // Nonce nonce := make([]byte, gcm.NonceSize()) _, err = rand.Read(nonce) // Handle Error if err != nil { return "", err } // Return Encrypted Data return base64.RawStdEncoding.EncodeToString(gcm.Seal(nonce, nonce, []byte(data), nil)), err }