3000 explained code solutions for 75 technologies


golangHow to generate sha256 hash from string


package main

import (
  "fmt"
  "crypto/sha256"
)

func main() {
  str := "Hi all!"

  h := sha256.New()
  h.Write([]byte(str))
  hash := h.Sum(nil)
  
  fmt.Printf("%x", hash)
}ctrl + c
package main

default package declaration

"hash/sha256"

package to calculate SHA256 hashes

"Hi all!"

sample string to hash

sha256.New()

new shad56 hasher

h.Write([]byte(str))

pass our string to hasher

h.Sum(nil)

calculate and return hash