package main import ( "crypto/md5" "fmt" ) func main() { data := []byte("hello world") hash := md5.New() hash.Write(data) sum := hash.Sum(nil) fmt.Printf("%x\n", sum) }
package main import ( "crypto/sha256" "fmt" ) func main() { data := []byte("hello world") hash := sha256.New() hash.Write(data) sum := hash.Sum(nil) fmt.Printf("%x\n", sum) }In this example, we are using the sha256 package which also implements the hash.Hash interface. The usage is similar to the previous example, except we are using SHA256 hashing instead of MD5. These examples are using the Go built-in package libraries: md5 and sha256.