Refactored the BLAKE2 algorithm and updated it so it now returns the hash in hexadecimal.
parent
3f16795eb7
commit
66556d188f
@ -1,24 +1,27 @@
|
||||
package blake2
|
||||
|
||||
import (
|
||||
// Standard
|
||||
"encoding/hex"
|
||||
|
||||
// Standard Extended
|
||||
"golang.org/x/crypto/blake2b"
|
||||
)
|
||||
|
||||
// Hash
|
||||
func (algorithm Algorithm) Hash(data []byte) ([]byte, error) {
|
||||
func (algorithm Algorithm) Hash(data []byte) (string, error) {
|
||||
// Hasher
|
||||
hasher, err := blake2b.New(algorithm.size, nil)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
return []byte(""), err
|
||||
return "", err
|
||||
}
|
||||
// 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue