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.
55 lines
1.1 KiB
55 lines
1.1 KiB
package gomd5
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
func Php(str string) string {
|
|
h := md5.New()
|
|
io.WriteString(h, str)
|
|
return fmt.Sprintf("%x", h.Sum(nil))
|
|
}
|
|
|
|
func Md5(str string) string {
|
|
s := md5.New()
|
|
s.Write([]byte(str))
|
|
return hex.EncodeToString(s.Sum(nil))
|
|
}
|
|
|
|
// ToUpper md5加密后转大写
|
|
func ToUpper(str string) string {
|
|
h := md5.New()
|
|
h.Write([]byte(str))
|
|
cipherStr := h.Sum(nil)
|
|
return strings.ToUpper(hex.EncodeToString(cipherStr))
|
|
}
|
|
|
|
// ToLower md5加密后转小写
|
|
func ToLower(str string) string {
|
|
h := md5.New()
|
|
h.Write([]byte(str))
|
|
cipherStr := h.Sum(nil)
|
|
return strings.ToLower(hex.EncodeToString(cipherStr))
|
|
}
|
|
|
|
// GetMD5Encode 返回一个32位md5加密后的字符串
|
|
func GetMD5Encode(data string) string {
|
|
h := md5.New()
|
|
h.Write([]byte(data))
|
|
return hex.EncodeToString(h.Sum(nil))
|
|
}
|
|
|
|
// Get16MD5Encode 返回一个16位md5加密后的字符串
|
|
func Get16MD5Encode(data string) string {
|
|
return GetMD5Encode(data)[8:24]
|
|
}
|
|
|
|
// Get16MD5EncodeToUpper 返回一个16位md5加密后的大写字符串
|
|
func Get16MD5EncodeToUpper(data string) string {
|
|
return strings.ToUpper(Get16MD5Encode(data))
|
|
}
|