Go学习——密码学

Go学习——密码学

package main import ( "crypto/aes" "fmt" "strings" ) func main() { //------AES加密------// //秘钥 16/24/32bytes对应AES-128/AES-192/AES-256. key := []byte{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, } fmt.Println("每次加密的字节数:", aes.BlockSize) //明文 cleartext := make([]byte, aes.BlockSize) strings.NewReader("I'm a cleartext!").Read(cleartext) //密文 ciphertext := make([]byte, aes.BlockSize) cip, _ := aes.NewCipher(key) //加密 cip.Encrypt(ciphertext, cleartext) fmt.Println("明文:", cleartext) fmt.Println("密文:", ciphertext) //解密 cip.Decrypt(cleartext, ciphertext) fmt.Println("密文:", ciphertext) fmt.Println("明文:", cleartext) fmt.Printf("明文: %s", cleartext) //------AES加密------// }

转载于:https://my.oschina.net/u/1537881/blog/294829

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/109765.html原文链接:https://javaforall.net

(0)
上一篇 2021年8月30日 下午6:00
下一篇 2021年8月30日 下午7:00


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号