diff options
| author | Saumit Dinesan <justsaumit@protonmail.com> | 2023-09-05 11:34:21 +0530 | 
|---|---|---|
| committer | Saumit Dinesan <justsaumit@protonmail.com> | 2023-09-05 11:34:21 +0530 | 
| commit | 3833e32b70f10e54bba47c89f4aea78e828ea5b0 (patch) | |
| tree | 83673ebbb155a5bdb9c7ccbec9b88d5b3846e7af /hasher | |
| parent | 1b9421884f3d403e3406e61cee742bd03d3a0fa5 (diff) | |
Adding Blake2 Hashing with /hasher endpoint
Diffstat (limited to 'hasher')
| -rw-r--r-- | hasher/blake2-hash_generator.go | 30 | 
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 +}  | 
