In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-10-21 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
Editor to share with you how to use HTML to write notes, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it! Answer: use the syntax "
Wechat
About us
Contact us
Product review
car news
thenatureplanet
More Form oMedia:
AutoTimes.
Bestcoffee.
SL News.
Jarebook.
Coffee Hunters.
Sundaily.
Modezone.
NNB.
Coffee.
Game News.
FrontStreet.
GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.