diff options
Diffstat (limited to '')
-rw-r--r-- | core/crypt.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/core/crypt.go b/core/crypt.go new file mode 100644 index 0000000..6de70e6 --- /dev/null +++ b/core/crypt.go @@ -0,0 +1,25 @@ +package core + +import ( + "crypto/sha256" + "fmt" + "io" + "os" + "strings" +) + +func calculateStringHash(a string) (string, error) { + hash := sha256.New() + hash.Write([]byte(a)) + hashInBytes := hash.Sum(nil)[:20] + return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil +} + +func calculateFileHash(file *os.File) (string, error) { + hash := sha256.New() + if _, err := io.Copy(hash, file); err != nil { + return "", err + } + hashInBytes := hash.Sum(nil)[:20] + return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil +} |