From 4a0466f797dedf5dfe99d546bc6489b8d3bca094 Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 2 Nov 2020 14:06:34 +0100 Subject: [PATCH] Hash and VerifyHash utils --- utils/coreutils.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/utils/coreutils.go b/utils/coreutils.go index 499479629..ea3dc8ac3 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -993,3 +993,20 @@ func AESDecrypt(encrypted string, encKey string) (txt string, err error) { return fmt.Sprintf("%s", plaintext), nil } + +// Hash generates the hash text +func Hash(dataKeys ...string) (lns string, err error) { + var hashByts []byte + if hashByts, err = bcrypt.GenerateFromPassword( + []byte(ConcatenatedKey(dataKeys...)), + bcrypt.MinCost); err != nil { + return + } + return string(hashByts), nil +} + +// VerifyHash matches the data hash with the dataKeys ha +func VerifyHash(hash string, dataKeys ...string) bool { + err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(ConcatenatedKey(dataKeys...))) + return err == nil +}