What is the encryption and decryption of AES, DES and 3DES in Golang
This article shows you how to encrypt and decrypt AES, DES and 3DES in Golang. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Functional wrapper of the Openssl encryption:OpenSSL library for symmetric and asymmetric encryption and decryption.
Install go get-u github.com/thinkoner/openssl usage AES
The length of the key can be 16-24-32 characters (128 ram 192 ram 256 bits).
AES-ECB:
Src: = byte ("123456") key: = [] byte ("1234567890123456") dst, _: = openssl.AesECBEncrypt (src, key, openssl.PKCS7_PADDING) fmt.Printf (base64.StdEncoding.EncodeToString (dst)) / / yXVUkR45PFz0UfpbDB8/ew==dst, _ = openssl.AesECBDecrypt (dst, key, openssl.PKCS7_PADDING) fmt.Println (string (dst)) / / 123456
AES-CBC:
Src: = byte ("123456") key: = [] byte ("1234567890123456") iv: = [] byte ("1234567890123456") dst, _: = openssl.AesCBCEncrypt (src, key, iv, openssl.PKCS7_PADDING) fmt.Println (base64.StdEncoding.EncodeToString (dst)) / / 1jdzWuniG6UMtoa3T6uNLA==dst, _ = openssl.AesCBCDecrypt (dst, key, iv, openssl.PKCS7_PADDING) fmt.Println (string (dst)) / / 123456DES
The key must be 8 characters (64 bits) long.
DES-ECB:
Openssl.DesECBEncrypt (src, key, openssl.PKCS7_PADDING) openssl.DesECBDecrypt (src, key, openssl.PKCS7_PADDING)
DES-CBC:
Openssl.DesCBCEncrypt (src, key, iv, openssl.PKCS7_PADDING) openssl.DesCBCDecrypt (src, key, iv, openssl.PKCS7_PADDING) 3DES
The length of the key must be 24 characters (192 bits).
3DES-ECB:
Openssl.Des3ECBEncrypt (src, key, openssl.PKCS7_PADDING) openssl.Des3ECBDecrypt (src, key, openssl.PKCS7_PADDING)
3DES-CBC:
Openssl.Des3CBCEncrypt (src, key, iv, openssl.PKCS7_PADDING) openssl.Des3CBCDecrypt (src, key, iv, openssl.PKCS7_PADDING) the above content is what AES, DES, 3DES encryption and decryption are like in Golang. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.