package main import ( "crypto/sha256" "fmt" ) func main() { str := "example" h := sha256.Sum256([]byte(str)) fmt.Printf("SHA-256 hash of '%s': %x\n", str, h) }
package main import ( "crypto/md5" "fmt" ) func main() { str := "password" h := md5.Sum([]byte(str)) fmt.Printf("MD5 hash of '%s': %x\n", str, h) }This code uses the MD5 hash function from the crypto package to calculate the hash value of a given string. It calculates a hash value for the string "password" and prints the result in hexadecimal format. Package/library: Go crypto package