Skip to content

Instantly share code, notes, and snippets.

@mvrilo
Created April 28, 2013 20:37
Show Gist options
  • Select an option

  • Save mvrilo/5478325 to your computer and use it in GitHub Desktop.

Select an option

Save mvrilo/5478325 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/md5"
"crypto/sha1"
"encoding/hex"
"fmt"
"io"
)
type hash struct {
value string
}
func Digest(str string) *hash {
return &hash{str}
}
func (ha *hash) md5() string {
h := md5.New()
io.WriteString(h, ha.value)
return hex.EncodeToString(h.Sum(nil))
}
func (ha *hash) sha1() string {
h := sha1.New()
io.WriteString(h, ha.value)
return hex.EncodeToString(h.Sum(nil))
}
func main() {
fmt.Println(Digest("test").md5())
fmt.Println(Digest("test").sha1())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment