Skip to content

How to SHA256 a String in Golang

If you need to SHA256 a String in Go, then you can use the crypto/sha256 package.

SHA256 a String in Go

package main import ( "crypto/sha256" "fmt" ) func main() { s := "A sample string to SHA256!" h := sha256.New() h.Write([]byte(s)) bs := h.Sum(nil) fmt.Println(s) fmt.Printf("%x\n", bs) }
Code language: Go (go)

The output will look like this:

A sample string to SHA256! 9abf637c7e39cc4ef84d6d92cf7ffe168dc922b8ae666260d907e0353865ce89

See also  How to Efficiently Concatenate Strings in Go
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x