golang 计算文件MD5
bytes 是文件数据流
xalgorithm.MD5ToUpper32(hex.EncodeToString(bytes))
xalgorithm.MD5ToUpper32(hex.EncodeToString(bytes))package xalgorithmimport ("crypto/md5""fmt""io""strings"
)/*
MD5ToUpper32 将字符串,转为32位md5加密,返回大写字母
*/
func MD5ToUpper32(str string) string {w := md5.New()io.WriteString(w, str) //将str写入到w中md5Str := fmt.Sprintf("%x", w.Sum(nil)) //w.Sum(nil)将w的hash转成[]byte格式return strings.ToUpper(md5Str)
}/*
MD5ToLower32 将字符串,转为32位md5加密,返回小写字母
*/
func MD5ToLower32(str string) string {w := md5.New()io.WriteString(w, str) //将str写入到w中md5Str := fmt.Sprintf("%x", w.Sum(nil)) //w.Sum(nil)将w的hash转成[]byte格式return md5Str
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
