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 :
Advertisement
Something interesting
Tutorials
+17k Golang : Covert map/slice/array to JSON or XML format
+5k Linux : How to set root password in Linux Mint
+6k Golang : Experimenting with the Rejang script
+46.2k Golang : Read tab delimited file with encoding/csv package
+11.6k Golang : Simple file scaning and remove virus example
+5.8k Golang : Markov chains to predict probability of next state example
+7.5k Golang : Dealing with struct's private part
+11.8k Golang : Verify Linux user password again before executing a program example
+11.2k Golang : How to pipe input data to executing child process?
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+12.3k Golang : Validate email address
+11.9k Golang : Determine if time variables have same calendar day