You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
578 B
27 lines
578 B
package encryption |
|
|
|
import ( |
|
"math/rand" |
|
"time" |
|
) |
|
|
|
// using aes256, so 32 bytes-long key |
|
const KEYLEN uint = 32 |
|
const CHARS string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" |
|
|
|
// Generates 32 pseudo-random bytes to use as a key |
|
func Generate32AESkey() []byte { |
|
var generatedKey []byte |
|
|
|
rand.Seed(time.Now().UTC().UnixNano()) |
|
// choosing "random" 32 bytes from CHARS |
|
for { |
|
if len(generatedKey) == int(KEYLEN) { |
|
break |
|
} |
|
randomIndex := rand.Intn(len(CHARS)) |
|
generatedKey = append(generatedKey, CHARS[randomIndex]) |
|
} |
|
|
|
return generatedKey |
|
}
|
|
|