views:

249

answers:

1

I'm just starting with Golang and I am now stuck on MD5 creation. 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?

+2  A: 
  1 package main
  2 
  3 import (
  4     "fmt"
  5     "crypto/md5"
  6     "hash"
  7 )
  8 
  9 func main() {
 10     original := "my string comes here"
 11     var h hash.Hash = md5.New()
 12     h.Write([]byte(original))
 13     fmt.Printf("%s: %x\n", original, h.Sum())
 14 }
Stephen Hsu
strings.Bytes doesn't exist anymore on -release, it's []byte(original)
marketer