Skip to content

Instantly share code, notes, and snippets.

@jamescarr
Created June 7, 2017 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamescarr/85d1c439f52d92639af2a39041f98a2a to your computer and use it in GitHub Desktop.
Save jamescarr/85d1c439f52d92639af2a39041f98a2a to your computer and use it in GitHub Desktop.
package main
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"fmt"
"hash"
)
func hashIt(algo hash.Hash, s string) string {
algo.Write([]byte(s))
return fmt.Sprintf("%x", algo.Sum(nil))
}
func main() {
s := "Hello World"
fmt.Println(s)
fmt.Println(hashIt(md5.New(), s))
fmt.Println(hashIt(sha1.New(), s))
fmt.Println(hashIt(sha256.New(), s))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment