Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created July 1, 2018 00:15
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miguelmota/1f398eb5fb2666a037e6ed6fc9b119b0 to your computer and use it in GitHub Desktop.
Save miguelmota/1f398eb5fb2666a037e6ed6fc9b119b0 to your computer and use it in GitHub Desktop.
Golang SHA256 checksum of file
package main
import (
"crypto/sha256"
"fmt"
"io"
"log"
"os"
)
func main() {
f, err := os.Open("file.txt")
if err != nil {
log.Fatal(err)
}
defer f.Close()
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
}
fmt.Printf("%x", h.Sum(nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment