From 3833e32b70f10e54bba47c89f4aea78e828ea5b0 Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Tue, 5 Sep 2023 11:34:21 +0530 Subject: Adding Blake2 Hashing with /hasher endpoint --- hasher/blake2-hash_generator.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 hasher/blake2-hash_generator.go (limited to 'hasher/blake2-hash_generator.go') 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 +} -- cgit v1.2.3