Files
orbits/internal/crypto/crypto.go
T
2026-04-21 16:27:04 +02:00

28 lines
461 B
Go

package crypto
import (
"crypto/sha512"
"encoding/hex"
"io"
"os"
)
func CalculateHash(p string) (string, error) {
f, err := os.Open(p)
if err != nil {
return "", err
}
defer f.Close()
h := sha512.New()
if _, err := io.Copy(h, f); err != nil {
return "", err
}
sum := h.Sum(nil)
// return the sha checksum in hex
return hex.EncodeToString(sum), nil
// alternatively return in base64
//return base64.StdEncoding.EncodeToString(sum), nil
}