July 2017
Beginner to intermediate
358 pages
10h 54m
English
Symmetrical encryption also has its uses: for one, it is faster, and the other reason is that it can handle a message of any size. Implementing symmetrical encryption in Go is, as you would expect, quite straightforward: we have the excellent crypto/aes package that manages all the heavy lifting for us. Let's look at how we could encrypt a message with AES. Look at the example file, symmetric/symmetric.go:
12 func EncryptData(data []byte, key []byte) ([]byte, error) { 13 if err := validateKey(key); err != nil { 14 return make([]byte, 0), err 15 } 16 17 c, err := aes.NewCipher(key) 18 if err != nil { 19 return make([]byte, 0), err 20 } 21 22 gcm, err := cipher.NewGCM(c) 23 if err != nil { 24 return make([]byte, 0), err 25 } ...Read now
Unlock full access