20 lines
374 B
Go
20 lines
374 B
Go
package utility
|
|
|
|
import (
|
|
"crypto/sha512"
|
|
"encoding/hex"
|
|
"io"
|
|
)
|
|
|
|
func HashReader(r io.Reader) (string, error) {
|
|
h := sha512.New()
|
|
if _, err := io.Copy(h, r); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
// return the sha checksum in hex
|
|
return hex.EncodeToString(h.Sum(nil)), nil
|
|
// alternatively return in base64
|
|
//return base64.StdEncoding.EncodeToString(h.Sum(nil)), nil
|
|
}
|