summaryrefslogtreecommitdiff
path: root/hasher
diff options
context:
space:
mode:
Diffstat (limited to 'hasher')
-rw-r--r--hasher/blake2-hash_generator.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/hasher/blake2-hash_generator.go b/hasher/blake2-hash_generator.go
new file mode 100644
index 0000000..4d85a58
--- /dev/null
+++ b/hasher/blake2-hash_generator.go
@@ -0,0 +1,30 @@
+package hasher
+
+import (
+ "fmt"
+ "golang.org/x/crypto/blake2b"
+ "io"
+ "os"
+)
+
+func CalculateBLAKE2Hash(filePath string) (string, error) {
+ file, err := os.Open(filePath)
+ if err != nil {
+ return "", err
+ }
+ defer file.Close()
+
+ hash, err := blake2b.New256(nil)
+ if err != nil {
+ return "", err
+ }
+
+ _, err = io.Copy(hash, file)
+ if err != nil {
+ return "", err
+ }
+
+ hashBytes := hash.Sum(nil)
+ hashString := fmt.Sprintf("%x", hashBytes)
+ return hashString, nil
+}