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
+5.4k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+18.4k Golang : Read binary file into memory
+10.6k Golang : Resolve domain name to IP4 and IP6 addresses.
+5.8k Cash Flow : 50 days to pay your credit card debt
+30.9k Golang : Interpolating or substituting variables in string examples
+5.8k Golang : Find change in a combination of coins example
+7.1k Golang : Squaring elements in array
+19.8k Golang : Append content to a file
+9.4k Golang : Generate EAN barcode
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+18.5k Golang : Set, Get and List environment variables
+24k Golang : Call function from another package