This is a creation in Article, where the information may have evolved or changed.
There are several ways to connect a go string, and the BUF buffer method executes faster, and the method needs to contain a package that is: "Byte"
Go MD5 encryption method, here directly to a string of strings to calculate the MD5. among them, through MD5. New () Initializes a MD5 object, which is actually a hash. The hash object. The function prototype is func New() hash.Hash
.
The object implements a hash. Hash sum interface: calculates the checksum. Its function func Sum(data []byte) [Size]byte
is a prototype of a hash. The content stored inside the hash object is checksum computed and then appended to data to form a new byte slice, so the usual use is to set data to nil.
The method returns a size byte array, which is a 128bit 16-byte byte array for MD5. Here, you convert a string into a byte array by []byte (), and you can also convert it through the other interfaces of byte.
Package Main
Import (
"Bytes"
"FMT"
"Crypto/md5"
"Encoding/hex"
)
Func Main () {
str: = "something"
STR2: = "Nanalihai"
BUF: = bytes. Newbufferstring (str)
Buf. Write ([]byte (STR2))
Fmt. Println (BUF. String ())//Output stitching result of two strings
H: = MD5. New ()
H.write ([]byte (BUF. String ()))//BUF is required for encryption. String ()
Fmt. Printf ("%s\n", Hex. Encodetostring (H.sum (nil)))//Output encryption result
}
The result of the operation is: