Files
zmkgC/api/v1/common/coryCommon/md5.go
2025-07-07 20:11:59 +08:00

24 lines
641 B
Go

package coryCommon
import (
"crypto/md5"
"encoding/hex"
"strings"
)
// MD5Hash 将字符串进行 MD5 加密,并返回 32 位长度的 MD5 散列值
func MD5Hash(input string) string {
// 将输入字符串转换为小写,以确保不区分大小写
input = strings.ToLower(input)
// 创建 MD5 散列对象
md5Hash := md5.New()
// 将输入字符串转换为字节数组,并传递给 MD5 散列对象
_, _ = md5Hash.Write([]byte(input))
// 计算 MD5 散列值
hashBytes := md5Hash.Sum(nil)
// 将散列值转换为 32 位的十六进制字符串
md5HashString := hex.EncodeToString(hashBytes)
return md5HashString
}