HiveBrain v1.2.0
Get Started
← Back to all entries
snippetgoCritical

How to get a MD5 hash from a string in Golang?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howmd5fromgolanghashstringget

Problem

This is how I started to get a md5 hash from a string:

import "crypto/md5"

var original = "my string comes here"
var hash = md5.New(original)


But obviously this is not how it works. Can someone provide me a working sample for this?

Solution

Reference Sum,For me,following work well:

package main

import (
    "crypto/md5"
    "fmt"
)

func main() {
    data := []byte("hello")
    fmt.Printf("%x", md5.Sum(data))
}

Code Snippets

package main

import (
    "crypto/md5"
    "fmt"
)

func main() {
    data := []byte("hello")
    fmt.Printf("%x", md5.Sum(data))
}

Context

Stack Overflow Q#2377881, score: 114

Revisions (0)

No revisions yet.