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.