博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Golang AES加密
阅读量:7250 次
发布时间:2019-06-29

本文共 1275 字,大约阅读时间需要 4 分钟。

版权声明:本文可能为博主原创文章,若标明出处可随便转载。 https://blog.csdn.net/Jailman/article/details/81188883
package mainimport (    "crypto/aes"    "crypto/cipher"    "fmt"    "os")var commonIV = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}func main() {    //password length must be under 30    password := []byte("thisisthepassword")    //key string    key := "s8*WQ0@KO#CN*raoua8ofCTx*oxqCk46"    ciphercode := Encrypt(key, password)    Decrypt(key, ciphercode)}func Encrypt(key string, password []byte) []byte {    //create aes    c, err := aes.NewCipher([]byte(key))    if err != nil {        fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key), err)        os.Exit(-1)    }    //encrypt string    cfb := cipher.NewCFBEncrypter(c, commonIV)    ciphertext := make([]byte, len(password))    cfb.XORKeyStream(ciphertext, password)    return ciphertext}func Decrypt(key string, ciphercode []byte) []byte {    //create aes    c, err := aes.NewCipher([]byte(key))    if err != nil {        fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key), err)        os.Exit(-1)    }    //decrypt string    cfbdec := cipher.NewCFBDecrypter(c, commonIV)    password := make([]byte, 30)    cfbdec.XORKeyStream(password, ciphercode)    return password}
你可能感兴趣的文章
我的友情链接
查看>>
the dude 使用教程和一点感觉
查看>>
Spring4+Hibernate4 注解整合配置
查看>>
螺旋数字程序
查看>>
Pyhton 第九章 正则表达式
查看>>
mysql主从配置
查看>>
Jconsole远程监控tomcat 的JVM内存(linux、windows)
查看>>
分布式项目(一)iot-pt
查看>>
JFreeChart开源图表组件在Java开发中的应用(一)
查看>>
使用ZooKeeper ACL特性进行znode控制
查看>>
struts2 跳转类型介绍 result type=chain、dispatcher、redirect(redirect-action)
查看>>
宜春之行
查看>>
我的友情链接
查看>>
Exchange2010 dag 的缷载
查看>>
2011/11/14 1:52 坚持就会胜利
查看>>
oracle概念和术语 建表时的一些参数pctfree initrans maxtrans sto
查看>>
我的友情链接
查看>>
转ApplicationContext的三种实现方式以及在web.xml配置的两种方式
查看>>
【我的软考之路】我的网工备考之路~
查看>>
mysql5.7.10安装
查看>>