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
+6.1k Golang : Create new color from command line parameters
+9.4k Golang : Create unique title slugs example
+9.7k Golang : interface - when and where to use examples
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+6k Golang : Convert Chinese UTF8 characters to Pin Yin
+8.1k Golang : Randomize letters from a string example
+12.2k Golang : Simple client-server HMAC authentication without SSL example
+17.5k Golang : Find smallest number in array
+10.5k Golang : Select region of interest with mouse click and crop from image
+12.6k Golang : flag provided but not defined error
+29.4k Golang : JQuery AJAX post data to server and send data back to client example