Created
July 1, 2018 00:15
-
-
Save miguelmota/1f398eb5fb2666a037e6ed6fc9b119b0 to your computer and use it in GitHub Desktop.
Golang SHA256 checksum of file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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