How to hash a string with SHA-256 in Go

1 Answer

0 votes
package main

import (
    "crypto/sha256"
    "encoding/hex"
    "fmt"
)

func sha256Hash(input string) string {
    // Compute SHA‑256
    hash := sha256.Sum256([]byte(input))

    // Convert to hex string
    return hex.EncodeToString(hash[:])
}

func main() {
    input := "Go programming language"
    
    hash := sha256Hash(input)
    
    fmt.Println(hash)
}



/*
run:

81d85c3f0f14302be4fd2fa4209bb3914f328b07ad5975d44bdd32a0177b0aa6

*/

 



answered 7 hours ago by avibootz
...