file-checksum-monitor/internal/library/checksum.go
2024-12-10 19:21:07 -03:00

25 lines
374 B
Go

package library
import (
"crypto/sha256"
"encoding/hex"
"io/ioutil"
"os"
)
func calculateChecksum(filePath string) (string, error) {
file, err := os.Open(filePath)
if err != nil {
return "", err
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
return "", err
}
hash := sha256.Sum256(data)
return hex.EncodeToString(hash[:]), nil
}