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
+22.1k Golang : Print out struct values in string format
+8.8k Golang : Convert octal value to string to deal with leading zero problem
+5.8k Golang : Takes a plural word and makes it singular
+5k PHP : How to check if an array is empty ?
+7.7k Golang : Capture text return from exec function example
+3.8k Which content-type(MIME type) to use for JSON data
+8.9k CodeIgniter : Load different view for mobile devices
+17.8k Golang : Clearing slice
+6.8k Golang : Get all countries phone codes
+13.3k Golang : Save(pipe) HTTP response into a file
+25.9k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+28.5k Golang : How to get HTTP request header information?