diff --git a/algorithms/sha256/algorithm.go b/algorithms/sha256/Algorithm.go similarity index 77% rename from algorithms/sha256/algorithm.go rename to algorithms/sha256/Algorithm.go index f878f28..140dbb2 100644 --- a/algorithms/sha256/algorithm.go +++ b/algorithms/sha256/Algorithm.go @@ -4,7 +4,7 @@ package sha256 type Algorithm struct{} // New -func New(size int) Algorithm { +func New() Algorithm { // Return Algorithm return Algorithm{} } diff --git a/algorithms/sha256/CheckHash.go b/algorithms/sha256/CheckHash.go index 5f3b23c..c30115e 100644 --- a/algorithms/sha256/CheckHash.go +++ b/algorithms/sha256/CheckHash.go @@ -4,10 +4,11 @@ import ( // Standard "crypto/sha256" "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 := sha256.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/sha256/Hash.go b/algorithms/sha256/Hash.go index 885acd0..3d3adf1 100644 --- a/algorithms/sha256/Hash.go +++ b/algorithms/sha256/Hash.go @@ -3,18 +3,19 @@ package sha256 import ( // Standard "crypto/sha256" + "encoding/hex" ) // Hash -func (Algorithm) Hash(data []byte) ([]byte, error) { +func (Algorithm) Hash(data []byte) (string, error) { // Hasher hasher := sha256.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 }