Aller au contenu

Hachage SHA256

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.

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))
}
Fenêtre de terminal
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9