package main import ( "crypto/aes" "encoding/hex" "fmt" ) func main() { // cipher key key := "thisis32bitlongpassphraseimusing" // plaintext pt := "This is a secret" c := EncryptAES([]byte(key), pt) // plaintext fmt.Println((pt)) fmt.Println([]byte(pt)) // ciphertext fmt.Println((c)) fmt.Println([]byte(c)) key2 := "thisis32bitlongpassphraseimusing" // decrypt DecryptAES([]byte(key2), c) } func EncryptAES(key []byte, plaintext string) string { c, err := aes.NewCipher(key) CheckError(err) out := make([]byte, len(plaintext)) c.Encrypt(out, []byte(plaintext)) return hex.EncodeToString(out) } func DecryptAES(key []byte, ct string) { ciphertext, _ := hex.DecodeString(ct) c, err := aes.NewCipher(key) CheckError(err) pt := make([]byte, len(ciphertext)) c.Decrypt(pt, ciphertext) s := string(pt[:]) fmt.Println("DECRYPTED:", s) } func CheckError(err error) { if err != nil { panic(err) } }