Golang crypto/sha256 functions example
package crypto/sha256
Package sha256 implements the SHA224 and SHA256 hash algorithms as defined in FIPS 180-4.
Golang crypto/sha256 functions usage example
package main
import (
"crypto/sha256"
"fmt"
"io"
)
func main() {
h256 := sha256.New()
io.WriteString(h256, "Hello money money!")
fmt.Printf("Hash256 : %x\n", h256.Sum(nil))
h224 := sha256.New224()
io.WriteString(h224, "Hello money money!")
fmt.Printf("Hash224 : %x\n", h224.Sum(nil))
// const Size224 = 28 bytes
data224 := []byte("Hello World!")
fmt.Printf("SHA224 checksum : %x\n", sha256.Sum224(data224))
data := []byte("Hello World!") // const Size = 32 bytes
fmt.Printf("SHA256 checksum : %x\n", sha256.Sum256(data))
}
Output :
go run sha256.go
Hash256 : 2a590667731adefb6afabc7fc539d4934ccd1dd43cc808a76e2d9528d237537c
Hash224 : 90653e56b9a4fa7927f7f3087e77f338d25eacb61cd2339968948115
SHA224 checksum : 4575bb4ec129df6380cedde6d71217fe0536f8ffc4e18bca530a7a1b
SHA256 checksum : 7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069
Reference :
Advertisement
Something interesting
Tutorials
+11.6k Golang : Convert(cast) float to int
+9.9k Golang : ffmpeg with os/exec.Command() returns non-zero status
+18.1k Golang : Check if a directory exist or not
+8.5k Golang : How to check variable or object type during runtime?
+20.9k Golang : Convert PNG transparent background image to JPG or JPEG image
+9.5k Golang : Accessing content anonymously with Tor
+7.4k Golang : Check to see if *File is a file or directory
+34.6k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+41k Golang : How to check if a string contains another sub-string?
+9.8k Golang : Resumable upload to Google Drive(RESTful) example
+10.8k Android Studio : Checkbox for user to select options example
+28.5k Golang : Change a file last modified date and time