The example in this article describes how the go language SHA1 hash of strings. Share to everyone for your reference. Specifically as follows:
Copy Code code as follows:
Package Main
Import (
"FMT"
"Crypto/md5"
"CRYPTO/SHA1"
"IO"
)
MD5 hash of a string
Func A (data string) string {
T: = MD5. New ();
Io. WriteString (T,data);
Return FMT. Sprintf ("%x", T.sum (nil));
}
SHA1 hash of a string
Func b (Data string) string {
T: = SHA1. New ();
Io. WriteString (T,data);
Return FMT. Sprintf ("%x", T.sum (nil));
}
Func Main () {
var data string = "abc";
Fmt. Printf ("MD5:%s\n", A (data));
Fmt. Printf ("SHA1:%s\n", B (data));
}
The output results are as follows:
Copy Code code as follows:
D:\workspace\golang>getmd5andsha1.exe
Md5:900150983cd24fb0d6963f7d28e17f72
sha1:a9993e364706816aba3e25717850c26c9cd0d89d
I hope this article will help you with your go language program.