26 lines
418 B
Go
26 lines
418 B
Go
package main
|
|
|
|
import (
|
|
"crypto/sha512"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func HashFile(path string) ([sha512.Size]byte, error) {
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
return [sha512.Size]byte{}, err
|
|
}
|
|
defer file.Close()
|
|
|
|
hasher := sha512.New()
|
|
if _, err := io.Copy(hasher, file); err != nil {
|
|
return [sha512.Size]byte{}, err
|
|
}
|
|
|
|
res := [sha512.Size]byte{}
|
|
hash := hasher.Sum(nil)
|
|
copy(res[:], hash)
|
|
return res, nil
|
|
}
|