Go language method for SHA1 hashing of strings _golang

Source: Internet
Author: User
Tags hash md5 md5 hash sha1 sha1 hash sprintf

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.

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.