SHA256 Hashes
// Importing necessary packages.
import (
"crypto/sha256"
"fmt"
)
// The main function, where the execution of the program begins.
func main() {
// The string to be hashed.
s := "sha256 this string"
// Creating a new SHA-256 hash object.
h := sha256.New()
// Writing the bytes of the string to the hash object.
h.Write([]byte(s))
// Calculating the SHA-256 hash and getting the hash in bytes.
bs := h.Sum(nil)
// Printing the original string and the hexadecimal representation of the hash.
fmt.Println(s)
fmt.Printf("%x\n", bs)
}Output
Last updated