package main import ( "crypto/md5" "fmt" "io" ) // golang md5加密 func main() { h := md5.New() // 签名 sign := "wasdhasdhjasduh" // 生成md5码写法1 io.WriteString(h, sign) sum := fmt.Sprintf("%x", h.Sum(nil)) fmt.Println("sum:", sum) // 生成md5码写法2 data := []byte("wasdhasdhjasduh") sum = fmt.Sprintf("%x\n", md5.Sum(data)) fmt.Println("sum:", sum) //sum: f4879827716b8ce02a04708ba09a04a6 //sum: f4879827716b8ce02a04708ba09a04a6 }
有疑问加站长微信联系(非本文作者)