-
-
Save Clivern/c8f9ccf07698507e5e4e1066b952750d to your computer and use it in GitHub Desktop.
Golang SHA256 checksum of file
This file contains 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