1 Star 0 Fork 0

marcello / go-common

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
md5.go 487 Bytes
一键复制 编辑 原始数据 按行查看 历史
marcello 提交于 2021-01-31 04:33 . update
package crypto
import (
"crypto/md5"
"encoding/hex"
"io"
"os"
)
// Md5 计算md5值
func Md5(s []byte) string {
m := md5.New()
m.Write(s)
return hex.EncodeToString(m.Sum(nil))
}
// FileMd5 计算文件md5值
func FileMd5(file string) (string, error) {
f, err := os.Open(file)
if err != nil {
return "", err
}
defer func() {
_ = f.Close()
}()
m := md5.New()
if _, err = io.Copy(m, f); err != nil {
return "", err
}
return hex.EncodeToString(m.Sum(nil)), nil
}
Go
1
https://gitee.com/marcellos/go-common.git
git@gitee.com:marcellos/go-common.git
marcellos
go-common
go-common
e809a504da49

搜索帮助

53164aa7 5694891 3bd8fe86 5694891