美文网首页
md5 python/golang

md5 python/golang

作者: 夜空一起砍猩猩 | 来源:发表于2018-07-31 14:02 被阅读0次

go example:

package main

import (

    "fmt"

    "crypto/md5"

     "strings"

)

func main() {

    str := "4c:bd:4e:0b:f8:1D"

    //str := "你好"

    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()

//str= u"你好"

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

相关文章

网友评论

      本文标题:md5 python/golang

      本文链接:https://www.haomeiwen.com/subject/zbxhvftx.html