Golang Encryption and decryption

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
Package Commonimport ("Crypto/md5" "Crypto/rand" "Encoding/base64" "Encoding/hex" "IO" "strings") const (//BASE64 character Do not have duplicate base64table = "<>:;",./?~!@# $CDVWX%^&*abyzabcghijklmnopqrstuvwxyz01efghijklmnopqrstu2345678 (Def) _ +| {}[]9/"Hashfunctionheader =" Zh.ife.iya "Hashfunctionfooter =" 09.o25. O20.78 ")/** * MD5 Encryption of a string, non-decryption */func getmd5string (s String) string {h: = MD5. New () H.write ([]byte (S + "Zhifeiya"))//hash value with Zhifeiya name, do not change to return hex after setting. Encodetostring (H.sum (nil))}/** * Gets a GUID value */func getguid () string {b: = make ([]byte,) If _, err: = Io. Readfull (Rand. Reader, B); Err! = Nil {return "" "}return getmd5string (base64. Urlencoding.encodetostring (b))}var coder = base64.  Newencoding (base64table)/** * Base64 encrypt */func base64encode (str string) string {var src []byte = []byte] (Hashfunctionheader + str + hashfunctionfooter) return string ([]byte (coder. Encodetostring (SRC))}/** * Base64 decryption */func Base64decode (str string) (string, error) {var src []byte = []byte (str) by, err : = Coder. Decodestring (string (src)) return strings. Replace (Strings. Replace (String (by), Hashfunctionheader, "",-1), Hashfunctionfooter, "",-1), err}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.