In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use DES in golang. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Package utilimport ("bytes"crypto/cipher"crypto/des"encoding/base64") var (iv = [] byte {1, 2, 3, 4, 5, 6, 7, 8} key = [] byte ("java")) / / DES encryption func DesEncrypt (data [] byte) string {result, _: = DesEncrypt (data, key) Iv) return base64.StdEncoding.EncodeToString (result)} / / DES decrypt func DesDecrypt (base64Str string) string {result, err: = base64.StdEncoding.DecodeString (base64Str) if err! = nil {return ""} origData, err: = DesDecrypt (result, key, iv) if err! = nil {return ""} return string (origData)} func DesEncrypt (origData, key) Iv [] byte) ([] byte, error) {block, err: = des.NewCipher (key) if err! = nil {return nil, err} origData = PKCS5Padding (origData, block.BlockSize () blockMode: = cipher.NewCBCEncrypter (block, iv) crypted: = make ([] byte, len (origData)) blockMode.CryptBlocks (crypted, origData) return crypted, nil} func DesDecrypt (crypted Key, iv [] byte) ([] byte, error) {block, err: = des.NewCipher (key) if err! = nil {return nil, err} blockMode: = cipher.NewCBCDecrypter (block, iv) origData: = make ([] byte, len (crypted) blockMode.CryptBlocks (origData, crypted) origData = PKCS5UnPadding (origData) return origData Nil} func ZeroUnPadding (origData [] byte) [] byte {return bytes.TrimRightFunc (origData, func (r rune) bool {return r = = rune (0)}) func PKCS5Padding (ciphertext [] byte, blockSize int) [] byte {padding: = blockSize-len (ciphertext)% blockSize padtext: = bytes.Repeat ([] byte {byte (padding)}, padding) return append (ciphertext) Padtext...)} func PKCS5UnPadding (origData [] byte) [] byte {length: = len (origData) unpadding: = int (origDB [length-1]) return origData [: (length- unpadding)]} about "how to use DES in golang" ends here Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.