awesome-go/impl/files-manipulation/29-HashAndChecksum.go

31 lines
497 B
Go
Raw Normal View History

package main
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"fmt"
"io/ioutil"
"log"
)
func main() {
/*
Hashing and Checksums
*/
// Get bytes from file
data, err := ioutil.ReadFile("test.txt")
if err != nil {
log.Fatal(err)
}
// Hash the file and output results
fmt.Printf("Md5: %x\n\n", md5.Sum(data))
fmt.Printf("Sha1: %x\n\n", sha1.Sum(data))
fmt.Printf("Sha256: %x\n\n", sha256.Sum256(data))
fmt.Printf("Sha512: %x\n\n", sha512.Sum512(data))
}