Golang : md5 hash of a string
This is the simplified version of the previous tutorial on generating checksum in Go. The aim is to learn about generating md5 hash from a string instead of a file.
package main
import (
"fmt"
"io"
"crypto/md5"
)
func main() {
hash := md5.New()
io.WriteString(hash, "I don't want anyone else to know about this string message!") // append into the hash
fmt.Printf("%x", hash.Sum(nil))
}
Execute >go run md5str.go
and you will see
f684c935121d80cc91398db196fef6b1
as the output. To change the crypto algorithm, just replace md5 with SHA1, SHA256 easily by changing the crypto package.
Hope you can learn something here.
Reference :
See also : Generate checksum for a file in Go
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+2.6k Linux/MacOSX : Search for files by filename and extension with find command
+2.4k Golang : Calculate BMI and risk category
+4.3k Golang : Go as a script or running go with shebang/hashbang style
+10.1k Golang : Convert PNG transparent background image to JPG or JPEG image
+4.4k Golang : Text file editor (accept input from screen and save to file)
+13k Golang : How to read integer value from standard input ?
+8k Golang : How to tell if a file is compressed either gzip or zip ?
+5.6k Golang : Listen and Serve on sub domain example
+1.2k Golang : Calculate a pip value and distance to target profit example
+4.2k Golang : Test a slice of integers for odd and even numbers
+4.6k Setting $GOPATH environment variable for Unix/Linux and Windows
+23.9k Golang : Upload and download file to/from AWS S3