md5 python/golang
夜空一起砍猩猩 · · 1676 次点击 · · 开始浏览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
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
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