2018-05-31 07:13:34 -05:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/md5"
|
|
|
|
"encoding/hex"
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Md5Sum calculates the md5sum of a stream
|
|
|
|
func Md5Sum(reader io.Reader) (string, error) {
|
|
|
|
var returnMD5String string
|
|
|
|
hash := md5.New()
|
|
|
|
if _, err := io.Copy(hash, reader); err != nil {
|
|
|
|
return returnMD5String, err
|
|
|
|
}
|
|
|
|
hashInBytes := hash.Sum(nil)[:16]
|
|
|
|
returnMD5String = hex.EncodeToString(hashInBytes)
|
|
|
|
return returnMD5String, nil
|
|
|
|
}
|
|
|
|
|
2019-01-28 15:09:40 -06:00
|
|
|
// Md5SumString calculates the md5sum of a string
|
2018-05-31 07:13:34 -05:00
|
|
|
func Md5SumString(input string) (string, error) {
|
|
|
|
buffer := strings.NewReader(input)
|
|
|
|
return Md5Sum(buffer)
|
|
|
|
}
|