This is a creation in Article, where the information may have evolved or changed. the use of the various encryption algorithms in the Go language
Encryption algorithms are often used in the encapsulation of data transfer, and see how to use the Go language library to encapsulate the encryption algorithm. Look directly at the code.
Package Main
Import(
"Encoding/base64"
"Crypto/md5"
"Encoding/hex"
"FMT"
)
Constbase64table=" abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/"
varcoder=base64. Newencoding (base64table)
Funcbase64encode (encode_byte[]byte)[]byte{
return[]byte(coder. Encodetostring (Encode_byte))
}
Funcbase64decode (decode_byte[]byte)([]byte, Error){
returncoder. Decodestring (string(Decode_byte))
}
FuncMD5 (b[]byte)string{
H: =MD5. New ()
H.write (b)
X: =h.sum (nil)
Y: =make ([]byte,+)
Hex. Encode (y,x)
returnstring(y)
}
FuncMain (){
encode_str: ="blog address: http://blog.csdn.net/bojie5744"
decode_byte: =Base64Encode ([]byte(ENCODE_STR))
FMT. Printf ("%s\n",string(Decode_byte))
Encode_byte,_: =base64decode (decode_byte)
FMT. Println (string(Encode_byte))
FMT. Println (MD5 ([]byte(ENCODE_STR)))
}