Last active
February 5, 2020 10:59
-
-
Save VMuliadi/c4b86f3ab43dba85995f1525c41c81d2 to your computer and use it in GitHub Desktop.
Get SHA256 from file in golang
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 ( | |
"bufio" | |
"crypto/sha256" | |
"encoding/hex" | |
"fmt" | |
"os" | |
) | |
func main() { | |
uploadedFile, _ := os.Open(filename) | |
fileStat, _ := uploadedFile.Stat() | |
bytes := make([]byte, fileStat.Size()) | |
buffer := bufio.NewReader(uploadedFile) | |
_, err := buffer.Read(bytes) | |
if err != nil { | |
panic(err) | |
} | |
sha256sumtext := sha256.Sum256(bytes) | |
fmt.Printf("%s", hex.EncodeToString(sha256sumtext[:])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment