1 Star 0 Fork 0

h79/goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
md5.go 671 Bytes
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2023-06-13 21:41 . filenmae to md5
package algorithm
import (
"crypto/md5"
"fmt"
"io"
"os"
)
func FileNameToMd5(filename string) string {
file, err := os.Open(filename)
defer file.Close()
if err != nil {
return ""
}
return FileToMd5(file)
}
func FileToMd5Byte(src io.Reader) []byte {
hash := md5.New()
if _, err := io.Copy(hash, src); err != nil {
return []byte{}
}
return hash.Sum(nil)
}
func FileToMd5(src io.Reader) string {
has := FileToMd5Byte(src)
return fmt.Sprintf("%x", has)
}
func StringToMd5(data string) string {
has := md5.Sum([]byte(data))
return fmt.Sprintf("%x", has)
}
func BytesToMd5(data []byte) string {
has := md5.Sum(data)
return fmt.Sprintf("%x", has)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.8.38

搜索帮助

344bd9b3 5694891 D2dac590 5694891