SHA256 hashes
Context
Section titled “Context”The crypto/sha256 package computes SHA‑256 hashes. Use sha256.Sum256 for a quick hash or sha256.New for streaming.
Example
Section titled “Example”Hash a string and a file (simulated).
Code example
Section titled “Code example”package main
import ( "crypto/sha256" "fmt")
func main() { data := []byte("hello world") hash := sha256.Sum256(data) fmt.Printf("%x\n", hash)
// Using New h := sha256.New() h.Write([]byte("hello ")) h.Write([]byte("world")) fmt.Printf("%x\n", h.Sum(nil))}Output
Section titled “Output”b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9