go - 在 Golang 中将 MD5 转换为十进制的最佳方法?

标签 go

在 Python 中我可以做到

int(hashlib.md5('hello world').hexdigest(), 16)

结果是

125893641179230474042701625388361764291L

Golang 中接受 MD5 字符串并获得十进制表示的等价物是什么?

最佳答案

您可以使用 math/big 执行此操作.

package main

import (
    "crypto/md5"
    "encoding/hex"
    "fmt"
    "math/big"
)

func main() {
    bi := big.NewInt(0)
    h := md5.New()
    h.Write([]byte("hello world"))
    hexstr := hex.EncodeToString(h.Sum(nil))
    bi.SetString(hexstr, 16)
    fmt.Println(bi.String())
}

http://play.golang.org/p/3h521Ao1UY

关于go - 在 Golang 中将 MD5 转换为十进制的最佳方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28128285/

相关文章:

networking - 尝试在 go 中实现端口扫描器

json - 去测试 map 之间的区别

go - 无法从 ssh 获取 stderr

amazon-web-services - 为什么在此AWS Lambda部署包中找不到处理程序脚本?

go - 通过docker连接golang和redis

go - 如何在没有隐式缓冲区的情况下将值从一个 Go channel 传输到另一个 channel ?

arrays - 戈朗 : calculate diff between two array of bytes and patch an array

json - 在redis中将结构存储为字符串

serialization - 如何在go中序列化/反序列化 map

go - 在 Go 中读取 CSV 文件