Skip to content

Instantly share code, notes, and snippets.

@Clivern
Forked from miguelmota/sha256file.go
Created May 29, 2019 23:58
Show Gist options
  • Save Clivern/c8f9ccf07698507e5e4e1066b952750d to your computer and use it in GitHub Desktop.
Save Clivern/c8f9ccf07698507e5e4e1066b952750d 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