简体   繁体   中英

Best way to convert an MD5 to decimal in Golang?

In Python I can do

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

which results in

125893641179230474042701625388361764291L

What's the equivalent in Golang to take an MD5 string and get the decimal representation?

You can do this with 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM