SHA256 of downloading files with Go verification

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

SHA256 of downloading files with Go verification

Originally on the use of computer and network security this piece is not enough attention, with the operating system for many years of piracy and Office software, in order to crack the use of various activation software, but also installed the use of a lot of other people cracked software; web-downloaded files are never verified. Slowly, more and more cautious, now only use the genuine Windows operating system, or open-source Linux operating system, open-source office software ... , in a word, the unknown software as far as possible, or on the virtual machine to use. Files downloaded from various official networks, if provided with a check code, be sure to verify the file.

From now on, go with go to implement SHA256 to verify the Golang official download of the Go installation file. Go Crypto package provides a lot of security-related algorithms, implementation of file SHA256 checksum is very simple, the following directly on the code.

Package Mainimport ("crypto/sha256" "FMT" "io" "Log" "OS") Func main () {if Len (OS. Args)! = 2 {fmt. Printf ("Usage:%s filename\n", OS. Args[0])}h: = sha256. New () F, err: = OS. OpenFile (OS. ARGS[1], OS. O_rdonly, 0666) if err! = Nil {log. Fatal (Err)}defer f.close () buf: = Make ([]byte, 1<<20) for {n, err: = Io. Readfull (f, buf) if Err = = Nil | | Err = = Io. errunexpectedeof {_, Err = H.write (buf[0:n]) if err! = Nil {log. Fatal (ERR)}} else if Err = = Io. EOF {break} else {log. Fatal (err)}}rslt: = H.sum (nil) fmt. Printf ("%x\n", Rslt)}

Go Build Build Sha256.exe

Download the latest Windows Installer go1.9.1.windows-386.msi check code from Golang official c939b62e32ba3048321546a111c732868b66fe1b58ae9c12b723a02a6a02b27c

After downloading the installation package, perform

D:\mygo\src\sha256>sha256.exe Go1.9.1.windows-386.msi
c939b62e32ba3048321546a111c732868b66fe1b58ae9c12b723a02a6a02b27c

Then the output of the Sha256.exe and the officially supplied parity pair

The Beyond CompAir comparison tool found that the downloaded file was correct.

With such a small piece of code, you can experience the strong go language, with go to achieve a variety of verification is easy. (Verification is only a small step in security, if a man-in-the-middle attack, page text and links are tampered with, verification success may be infected or infected horse files)

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.