awesome-go/impl/files-manipulation/28-HashAndChecksum.go
2024-01-20 10:55:19 +02:00

31 lines
486 B
Go

package main
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"fmt"
"os"
"log"
)
func main() {
/*
Hashing and Checksums
*/
// Get bytes from file
data, err := os.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))
}