While the task at hand is relatively straightforward, it turned out AES in Go is a bit clunky so I was wondering if this seems right. Also, any tips on Go coding in general are more than welcome.// Package aesjson provides a function to encode an object to JSON and apply// AES encryption to it.package aesjsonimport (    bytes    crypto/aes    crypto/cipher    crypto/rand    encoding/base64    encoding/json    io    log)const (    aesKey = U3RhY2tPdmVyZmxvdyBmb3IgdGhlIHdpbiEgICAgICA=)var (    aesCipher cipher.Block)func init() {    aesKeyDecoded, err := base64.StdEncoding.DecodeString(aesKey)    if err != nil {        log.Fatalln(err)    }    aesCipher, err = aes.NewCipher(aesKeyDecoded)    if err != nil {        log.Fatalln(err)    }}func spaces(c int) []byte {    return bytes.Repeat([]byte( ), c)}// EncodeJSON encodes the given object to JSON (via json.Marshal) and then// encrypts it using the AES encryption algorithm.// It returns the base64 of the encrypted JSON with the IV prepended to it.func EncodeJSON(val interface{}) (string, error) {    valjs, err := json.Marshal(val)    if err != nil {        return , err    }    paddingLen := 16 - len(valjs)%16    text := append(valjs, spaces(paddingLen)...)    ciphertext := make([]byte, aes.BlockSize+len(text))    iv := ciphertext[:aes.BlockSize]    if _, err := io.ReadFull(rand.Reader, iv); err != nil {        return , err    }    mode := cipher.NewCBCEncrypter(aesCipher, iv)    mode.CryptBlocks(ciphertext[aes.BlockSize:], text)    return base64.StdEncoding.EncodeToString(ciphertext), nil}And this is my test file - really interested if this is the right approach to testing a function like this.package aesjson_testimport (    crand crypto/rand    log    math/rand    testing    projectfolder/aesjson)func init() {    // Remove randomness    crand.Reader = rand.New(rand.NewSource(1))    log.Println(Randomness disabled!)}func TestEncode(t *testing.T) {    input := &aesjson.Token{        ID: 1234567890-1234567890,    }    want := Uv38ByGCZU8WP18PmmIdcprw1O0tpU/WBGgDIBYBpYaoJ2Lay7VnJGhKzswMb7ndHORd4kaege0cnsKkHMogTA==    got, err := aesjson.EncodeJSON(input)    if err != nil {        t.Fatalf(failed with error: %v, err)    }    if got != want {        t.Errorf(want: %q\ngot: %q, want, got)    }}
Encode object to JSON and encrypt with AES (with tests)
json;cryptography;go;aes