From e6ee7860b3adb7cfa52da01e2d9b30d8689e7baa Mon Sep 17 00:00:00 2001 From: amorozov Date: Tue, 25 Jun 2024 19:25:04 +0300 Subject: [PATCH] feature: hasher using hex strings now --- pkg/io/crypto/hasher/hasher.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/io/crypto/hasher/hasher.go b/pkg/io/crypto/hasher/hasher.go index 811b0c3..550fab4 100644 --- a/pkg/io/crypto/hasher/hasher.go +++ b/pkg/io/crypto/hasher/hasher.go @@ -3,6 +3,7 @@ package hasher import ( "crypto/md5" "crypto/sha256" + "encoding/hex" "hash" "io" "os" @@ -38,7 +39,7 @@ func (self *Hasher) GetFileHashString(fileLocation string) (string, error) { return "", err } - return string(bytes), nil + return convertBytesToString(bytes), nil } func (self *Hasher) GetFileHashBytes(fileLocation string) ([]byte, error) { @@ -57,7 +58,7 @@ func (self *Hasher) GetHashString(reader io.Reader) (string, error) { return "", err } - return string(bytes), nil + return convertBytesToString(bytes), nil } func (self *Hasher) GetHashBytes(reader io.Reader) ([]byte, error) { @@ -70,3 +71,7 @@ func (self *Hasher) GetHashBytes(reader io.Reader) ([]byte, error) { return hasher.Sum(nil), nil } + +func convertBytesToString(bytes []byte) string { + return hex.EncodeToString(bytes) +}