1 Star 1 Fork 0

湖底观景 / GolangTraining

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
GoesToEleven 提交于 2016-04-20 17:45 . changes dir structure
package main
import (
"crypto/aes"
"crypto/cipher"
"fmt"
)
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, _ := aes.NewCipher([]byte(key))
fmt.Printf("%d bytes NewCipher key with block size of %d bytes\n", len(key), block.BlockSize)
str := []byte("Hello World, and everyone else in the universe!")
// 16 bytes for AES-128, 24 bytes for AES-192, 32 bytes for AES-256
ciphertext := []byte("abcdef1234567890")
iv := ciphertext[:aes.BlockSize] // const BlockSize = 16
// encrypt
encrypter := cipher.NewCFBEncrypter(block, iv)
encrypted := make([]byte, len(str))
encrypter.XORKeyStream(encrypted, str)
fmt.Printf("%s encrypted to %v\n", str, encrypted)
// decrypt
decrypter := cipher.NewCFBDecrypter(block, iv) // simple!
decrypted := make([]byte, len(str))
decrypter.XORKeyStream(decrypted, encrypted)
fmt.Printf("%v decrypt to %s\n", encrypted, decrypted)
}
// https://www.socketloop.com/tutorials/golang-how-to-encrypt-with-aes-crypto
1
https://gitee.com/zhangjianGood/GolangTraining.git
git@gitee.com:zhangjianGood/GolangTraining.git
zhangjianGood
GolangTraining
GolangTraining
afa19f5c43f3

搜索帮助