AES Key Generation (128, 256 byte)

The “key” is whatever you generate from crypto/rand - in your case, a []byte from rand.Read. The number of bytes will depend on whether you’re using AES-128 (16 byte key) or AES-256 (32 byte key).

However, you also need to decide what mode of AES you’re using. I strongly, strongly suggest you use secretbox — I don’t mean to be rude (at all), but if you’re handling key material and you don’t know how to generate an AES key (or which mode you’re using), then you’re potentially creating a security risk for your customers.

In short:

  1. Re-think your approach (why do you need to encrypt things? Can you not use another service?)
  2. If you must, use secretbox, and generate keys securely
  3. Store the keys securely (this is non-trivial).