Standard library / crypto

crypto.Hash.New()

Create a fresh hash via the registered constructor. Panics when unavailable; check Available first. Expected stdout: 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad\n'.

Formal Syntax & Structure

go syntaxgo
func (h Hash) New() hash.Hash

Return Value

hash.Hash

Fresh hash instance.

Working Example

Example Snippetgo
package main
import (  "crypto"  _ "crypto/sha256"  "fmt")
func main() {  if !crypto.SHA256.Available() {    panic("missing SHA256")  }  h := crypto.SHA256.New()  h.Write([]byte("abc"))  fmt.Printf("%x\n", h.Sum(nil))}
Go Reference