完成基本的创建使用功能

This commit is contained in:
2024-09-11 20:19:47 +08:00
parent 28a84ad4d7
commit 951572a1f5
22 changed files with 783 additions and 31 deletions
+31
View File
@@ -0,0 +1,31 @@
package hash
import (
"crypto/md5"
"crypto/sha1"
"fmt"
)
// MD5 MD5哈希值
func MD5(b []byte) string {
h := md5.New()
_, _ = h.Write(b)
return fmt.Sprintf("%x", h.Sum(nil))
}
// MD5String MD5哈希值
func MD5String(s string) string {
return MD5([]byte(s))
}
// SHA1 SHA1哈希值
func SHA1(b []byte) string {
h := sha1.New()
_, _ = h.Write(b)
return fmt.Sprintf("%x", h.Sum(nil))
}
// SHA1String SHA1哈希值
func SHA1String(s string) string {
return SHA1([]byte(s))
}