|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|