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
+6.4k Golang : Gorrila mux.Vars() function example
+14.8k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+9.2k CodeIgniter : Load different view for mobile devices
+4k Facebook : How to place save to Facebook button on your website
+5.2k Golang : Compound interest over time example
+16.5k Golang : Defer function inside init()
+7.7k Android Studio : Image button and button example
+5.3k Golang : Get missing location after unmarshal binary and gob decode time.
+9.9k Golang : How to transmit update file to client by HTTP request example
+20.9k Golang : Join arrays or slices example
+29k Golang : How to verify uploaded file is image or allowed file types
+24.1k Golang : Convert long hexadecimal with strconv.ParseUint example