分享:用四十种语言分别写一个MD5算法 之12 Go语言MD5算法
package main
import (
"crypto/md5"
"fmt"
)
func main() {
for _, p := range [][2]string{
} {
validate(p[0], p[1])
}
}
var h = md5.New()
func validate(check, s string) {
h.Reset()
h.Write([]byte(s))
sum := fmt.Sprintf("%x", h.Sum())
if sum != check {
fmt.Println("MD5 fail")
fmt.Println(" for string,", s)
fmt.Println(" expected: ", check)
fmt.Println(" got: ", sum)
}
}
package main
import (
"crypto/md5"
"fmt"
)
func main() {
for _, p := range [][2]string{
} {
validate(p[0], p[1])
}
}
var h = md5.New()
func validate(check, s string) {
h.Reset()
h.Write([]byte(s))
sum := fmt.Sprintf("%x", h.Sum())
if sum != check {
fmt.Println("MD5 fail")
fmt.Println(" for string,", s)
fmt.Println(" expected: ", check)
fmt.Println(" got: ", sum)
}
}
有疑问加站长微信联系(非本文作者)