Sobes.tech
Middle

Can you give an example of a hash function?

sobes.tech AI

Answer from AI

In Go, the crypto or hash package is often used for hashing. For example, a simple hash function using SHA-256 from the crypto/sha256 package looks like this:

package main

import (
    "crypto/sha256"
    "fmt"
)

func main() {
    data := []byte("example data")
    hash := sha256.Sum256(data)
    fmt.Printf("Hash: %x\n", hash)
}

This code computes the SHA-256 hash of the string "example data" and outputs it in hexadecimal form.