You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
441 B
28 lines
441 B
package MD5Util
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
func MD5V1(str string) string {
|
|
h := md5.New()
|
|
h.Write([]byte(str))
|
|
return hex.EncodeToString(h.Sum(nil))
|
|
}
|
|
|
|
func MD5V2(str string) string {
|
|
data := []byte(str)
|
|
has := md5.Sum(data)
|
|
md5str := fmt.Sprintf("%x", has)
|
|
return md5str
|
|
}
|
|
|
|
func MD5V3(str string) string {
|
|
w := md5.New()
|
|
io.WriteString(w, str)
|
|
md5str := fmt.Sprintf("%x", w.Sum(nil))
|
|
return md5str
|
|
} |