title: How to calculate sha256 file checksum in Go
body: <p>I need utility for Windows that calculates sha256 file checksum so that when I download
  fedora I can verify checksum from here: <a href="https://fedoraproject.org/static/checksums/Fedora-18-i386-CHECKSUM" rel="noreferrer">https://fedoraproject.org/static/checksums/Fedora-18-i386-CHECKSUM</a></p>
  
  <p>Microsoft utility from <a href="http://support.microsoft.com/kb/889768" rel="noreferrer">http://support.microsoft.com/kb/889768</a> does only md5 and sha1.</p>
  
  <p>I don't want to use other downloadable tools that are not signed and not available from https or from sources that I don't know about, because it does not make any sense to download unsigned code over unencrypted connection or from untrusted source to verify signature of another code to trust it.</p>
  
  <p>Luckily google provides possibility to use https for all downloads so I can download Go over secure connection and start from there.</p>
  
  <p>Here is simple code that does that for a small file, but it's not very good for big files because it's not streaming.</p>
  
  <pre><code>package main
  
  import (
      "io/ioutil"
      "crypto/sha256"
      "os"
      "log"
      "encoding/hex"
  )
  
  func main() {
      hasher := sha256.New()
      s, err := ioutil.ReadFile(os.Args[1])    
      hasher.Write(s)
      if err != nil {
          log.Fatal(err)
      }
  
      os.Stdout.WriteString(hex.EncodeToString(hasher.Sum(nil)))
  }
  </code></pre>
  
  <p>How to make it to use streams so that it works on any file size.</p>