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
+7.2k Golang : Check to see if *File is a file or directory
+4.7k Golang : Calculate a pip value and distance to target profit example
+8.1k Useful methods to access blocked websites
+7.5k Golang : Test if an input is an Armstrong number example
+13k Golang : Linear algebra and matrix calculation example
+8k Golang : Check if integer is power of four example
+22.4k Golang : Strings to lowercase and uppercase example
+11.2k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+11.9k Golang : convert(cast) string to integer value
+5.6k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+30.6k Golang : Interpolating or substituting variables in string examples
+25.5k Golang : How to write CSV data to file