Hachage SHA256
Contexte
Section intitulée « Contexte »Le package crypto/sha256 calcule des hachages SHA‑256. Utilisez sha256.Sum256 pour un hachage rapide ou sha256.New pour un flux.
Hacher une chaîne.
Code exemple
Section intitulée « Code exemple »package main
import ( "crypto/sha256" "fmt")
func main() { donnees := []byte("bonjour monde") hash := sha256.Sum256(donnees) fmt.Printf("%x\n", hash)
// Avec New h := sha256.New() h.Write([]byte("bonjour ")) h.Write([]byte("monde")) fmt.Printf("%x\n", h.Sum(nil))}b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9