SHA256 hashes are frequently used to compute short identities for binary or text blobs. For example, TLS/SSL certificates use SHA256 to compute a certificate’s signature.
For convenience, compute a hash directly from a byte slice:
data := []byte("sha256 this string")hash := sha256.Sum256(data)fmt.Printf("%x\n", hash)// Output: 1af1dfa857bf1d8814fe1af8983c18080019922e557f15a8a0d3db739d77aacb
Use Sum256 when you have all the data at once. Use New() when you need to hash data incrementally.