This commit is contained in:
Yun
2023-12-27 19:00:14 +08:00
commit be8a2f84bd
12 changed files with 510 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
package md5x
import (
"crypto/md5"
"encoding/hex"
"io"
"os"
)
// 字符串的md5
func Md5String(value string) string {
m := md5.New()
m.Write([]byte(value))
return hex.EncodeToString(m.Sum(nil))
}
// 文件的md5
func Md5File(path string) (string, error) {
file, err := os.Open(path)
if err != nil {
return "", err
}
defer file.Close()
hash := md5.New()
io.Copy(hash, file)
return hex.EncodeToString(hash.Sum(nil)), nil
}