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
+4.5k Linux : sudo yum updates not working
+14.5k Golang : Send email with attachment(RFC2822) using Gmail API example
+9.6k Golang : List available AWS regions
+12.2k Golang : How to check if a string starts or ends with certain characters or words?
+32k Golang : Validate email address with regular expression
+14.7k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+12.5k Golang : Exit, terminating or aborting a program
+8.5k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+19.2k Golang : Get host name or domain name from IP address
+29.3k Golang : Saving(serializing) and reading file with GOB
+5.5k PHP : Convert CSV to JSON with YQL example
+19k Golang : Check whether a network interface is up on your machine