Generate SHA256 Hash
Examples in
Go
package main
import (
"crypto/sha256"
"fmt"
)
func main() {
s := "sha256 this string"
h := sha256.New()
// Write expects bytes. If you have a string s, use []byte(s) to coerce it to bytes.
h.Write([]byte(s))
// This gets the finalized hash result as a byte slice.
// The argument to Sum can be used to append to an existing byte slice: it usually isn’t needed.
bs := h.Sum(nil)
// Use the %x format verb to convert a hash results to a hex string.
fmt.Println(s)
fmt.Printf("%x\n", bs)
}
Last Run
:
sha256 this string
1af1dfa857bf1d8814fe1af8983c18080019922e557f15a8a0d3db739d77aacb