Golang crypto/aes.NewCipher() function example

package crypto/aes

NewCipher creates and returns a new cipher.Block. The key argument should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.

Golang crypto/aes.NewCipher() function usage example

 package main

 import (
 "fmt"
 "crypto/aes"
 )

 func main() {

 //The key argument should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
 key := "opensesame123456" // 16 bytes!

 block,err := aes.NewCipher([]byte(key))

 if err != nil {
 fmt.Println(err)
 }

 fmt.Printf("%d bytes NewCipher key with block size of %d bytes\n", len(key), block.BlockSize)
 }

Output :

16 bytes NewCipher key with block size of 8752 bytes

See also : https://www.socketloop.com/tutorials/golang-how-to-encrypt-with-aes-crypto

Reference :

http://golang.org/pkg/crypto/aes/#NewCipher

Advertisement