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

31 lines
486 B
Go
Raw Normal View History

package main
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"fmt"
2024-01-20 08:55:19 +00:00
"os"
"log"
)
func main() {
/*
Hashing and Checksums
*/
// Get bytes from file
2024-01-20 08:55:19 +00:00
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))
}