diff --git a/algorithms/sha512/algorithm.go b/algorithms/sha512/Algorithm.go similarity index 77% rename from algorithms/sha512/algorithm.go rename to algorithms/sha512/Algorithm.go index d53e308..b9fdcb4 100644 --- a/algorithms/sha512/algorithm.go +++ b/algorithms/sha512/Algorithm.go @@ -4,7 +4,7 @@ package sha512 type Algorithm struct{} // New -func New(size int) Algorithm { +func New() Algorithm { // Return Algorithm return Algorithm{} } diff --git a/algorithms/sha512/CheckHash.go b/algorithms/sha512/CheckHash.go index 49ebf62..bee3c1e 100644 --- a/algorithms/sha512/CheckHash.go +++ b/algorithms/sha512/CheckHash.go @@ -4,10 +4,11 @@ import ( // Standard "crypto/sha512" "crypto/subtle" + "encoding/hex" ) // Check Hash -func (Algorithm) CheckHash(data []byte, hashToCheck []byte) (bool, error) { +func (Algorithm) CheckHash(data []byte, hashToCheck string) (bool, error) { // Hasher hasher := sha512.New() // Write To Hasher @@ -16,6 +17,12 @@ func (Algorithm) CheckHash(data []byte, hashToCheck []byte) (bool, error) { if err != nil { return false, err } + // Decode Hash To Check + decodedHashToCheck, err := hex.DecodeString(hashToCheck) + // Handle Error + if err != nil { + return false, err + } // Return Hash - return subtle.ConstantTimeCompare(hasher.Sum(nil), hashToCheck) == 1, err + return subtle.ConstantTimeCompare(hasher.Sum(nil), decodedHashToCheck) == 1, err } diff --git a/algorithms/sha512/Hash.go b/algorithms/sha512/Hash.go index 8258178..b84a4c1 100644 --- a/algorithms/sha512/Hash.go +++ b/algorithms/sha512/Hash.go @@ -3,18 +3,19 @@ package sha512 import ( // Standard "crypto/sha512" + "encoding/hex" ) // Hash -func (Algorithm) Hash(data []byte) ([]byte, error) { +func (Algorithm) Hash(data []byte) (string, error) { // Hasher hasher := sha512.New() // Write To Hasher _, err := hasher.Write(data) // Handle Error if err != nil { - return []byte(""), err + return "", err } // Return Hash - return hasher.Sum(nil), err + return hex.EncodeToString(hasher.Sum(nil)), err }