Created
June 7, 2017 21:50
-
-
Save jamescarr/85d1c439f52d92639af2a39041f98a2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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