24 lines
534 B
Go
24 lines
534 B
Go
// cryptox 包示例:MD5 摘要(字符串、字节集、文件)
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"git.zeroonesoft.cn/golib/zogo/cryptox"
|
|
)
|
|
|
|
func main() {
|
|
// 字符串 / 字节集 MD5
|
|
md5sum, _ := cryptox.GetMd5ByStr("hello")
|
|
fmt.Println("MD5(hello):", md5sum)
|
|
|
|
// 文件 MD5
|
|
path := filepath.Join(os.TempDir(), "zogo-cryptox-demo.txt")
|
|
_ = os.WriteFile(path, []byte("hello"), 0644)
|
|
fileMd5, err := cryptox.GetFileMd5(path)
|
|
fmt.Println("文件 MD5:", fileMd5, "错误:", err)
|
|
_ = os.Remove(path)
|
|
}
|