# AES Key Generation (128, 256 byte)

**URL:** <https://forum.golangbridge.org/t/aes-key-generation-128-256-byte/2278>\
**Category:** Technical Discussion\
**Created:** [March 30, 2016, 2:18am UTC](https://forum.golangbridge.org/t/aes-key-generation-128-256-byte/2278 "2016-03-30T02:18:51Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![elithrar](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/elithrar/32/416_2.png) [@elithrar](https://forum.golangbridge.org/u/elithrar)\
**Post date:** [April 1, 2016, 3:45am UTC](https://forum.golangbridge.org/t/aes-key-generation-128-256-byte/2278/7 "2016-04-01T03:45:25Z")

</div>

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](https://godoc.org/golang.org/x/crypto/nacl/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).

---

_[View the full topic](https://forum.golangbridge.org/t/aes-key-generation-128-256-byte/2278)._
