06.md5 - wwj-2017-1117/AES_OK GitHub Wiki
package main
import ( "bytes" "crypto/md5" "encoding/hex" "fmt" "io" )
func main() { f1() f2() f3() }
func f1() { salt := "abc" m5 := md5.New() m5.Write([]byte("Mi Ma")) m5.Write([]byte(string(salt))) st := m5.Sum(nil) fmt.Println(st, hex.EncodeToString(st)) }
// 证明,加盐的确是追加$(salt) func f2() { m5 := md5.New() m5.Write([]byte("Mi Maabc")) st := m5.Sum(nil) fmt.Println(st, hex.EncodeToString(st)) }
// 一模一样 func f3() { md5h := md5.New() //buf:=bytes.Buffer{[]byte("Mi Maabc"),0,0}; buf := bytes.NewBuffer([]byte("Mi Maabc")) io.Copy(md5h, buf) st := md5h.Sum(nil) fmt.Println(st, hex.EncodeToString(st)) }
/* HMAC的图解 https://blog.csdn.net/chengqiuming/article/details/82822933 https://studygolang.com/articles/6900 */