|
|
@ -4,10 +4,11 @@ import (
|
|
|
|
// Standard
|
|
|
|
// Standard
|
|
|
|
"crypto/sha512"
|
|
|
|
"crypto/sha512"
|
|
|
|
"crypto/subtle"
|
|
|
|
"crypto/subtle"
|
|
|
|
|
|
|
|
"encoding/hex"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Check Hash
|
|
|
|
// Check Hash
|
|
|
|
func (Algorithm) CheckHash(data []byte, hashToCheck []byte) (bool, error) {
|
|
|
|
func (Algorithm) CheckHash(data []byte, hashToCheck string) (bool, error) {
|
|
|
|
// Hasher
|
|
|
|
// Hasher
|
|
|
|
hasher := sha512.New()
|
|
|
|
hasher := sha512.New()
|
|
|
|
// Write To Hasher
|
|
|
|
// Write To Hasher
|
|
|
@ -16,6 +17,12 @@ func (Algorithm) CheckHash(data []byte, hashToCheck []byte) (bool, error) {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode Hash To Check
|
|
|
|
|
|
|
|
decodedHashToCheck, err := hex.DecodeString(hashToCheck)
|
|
|
|
|
|
|
|
// Handle Error
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return false, err
|
|
|
|
|
|
|
|
}
|
|
|
|
// Return Hash
|
|
|
|
// Return Hash
|
|
|
|
return subtle.ConstantTimeCompare(hasher.Sum(nil), hashToCheck) == 1, err
|
|
|
|
return subtle.ConstantTimeCompare(hasher.Sum(nil), decodedHashToCheck) == 1, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|