Can anyone explain why these methods produce two different output values? It isn't clear from the md5 docs.
import (
"crypto/md5"
"encoding/hex"
"fmt"
)
func GetMD5HashWithWrite(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
func GetMD5HashWithSum(text string) string {
hasher := md5.New()
return hex.EncodeToString(hasher.Sum([]byte(text)))
}
See example: https://play.golang.org/p/Fy7KgfCvXc