go example:
package main
import (
"fmt"
"crypto/md5"
"strings"
)
func main() {
str := "4c:bd:4e:0b:f8:1D"
str = strings.ToLower(str)
fmt.Printf("str: %s\n",str)
data := []byte(str) has := md5.Sum(data)
md5str1 := fmt.Sprintf("%x", has)//将[]byte转成16进制
fmt.Printf("str MD5: %s\n", md5str1)
}
输出:
str: 4c:bd:4e:0b:f8:1d
str MD5: 8eb6f320a8c1e8a5f9d8351419f32b62
python example:
#! --coding: utf-8--
import hashlib
str= "4c:bd:4e:0b:f8:1D".lower()
h1 = hashlib.md5()
h1.update(str.encode(encoding="utf-8"))
print('str :' + str)
print('str MD5 :' + h1.hexdigest())
输出:
str :4c:bd:4e:0b:f8:1d
str MD5 :8eb6f320a8c1e8a5f9d8351419f32b62
有疑问加站长微信联系(非本文作者)