parent
6dc8583846
commit
31e3c67bf3
@ -0,0 +1,28 @@
|
|||||||
|
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
|
||||||
|
}
|
Loading…
Reference in new issue