Go MD5 HASH algorithm use

Source: Internet
Author: User
Tags md5 hash sha1 sha1 hash sprintf
This is a creation in Article, where the information may have evolved or changed. Package Main
Import(
  "Crypto/md5"
  "CRYPTO/SHA1"
  "FMT"
  "io"
)
MD5 hash of a string
FuncA (datastring) string  {
 t: =MD5. New()
 io. WriteString(t,data)
  returnto FMT. Sprintf("%x",t. Sum(nil))
}
SHA1 hash of a string
FuncB (datastring)string{
 t: =SHA1. New()
 io. WriteString(t,data)
  returnto FMT. Sprintf("%x",t. Sum(nil))
}
FuncMain (){
  vardata string="abc "
 ay: =a(data)
 Ah: =b(data)
 fmt. Println(ay)
      FMT  Printf (    :    %s\n "    ah 
 fmt. Printf("SHA1:%s\n",ah)
}
Results:
900150983cd24fb0d6963f7d28e17f72
sha2:a9993e364706816aba3e25717850c26c9cd0d89d
sha1:a9993e364706816aba3e25717850c26c9cd0d89d
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.