Skip to content
Node: crypto.createHash('sha256').update(d).digest('hex')github.com/sahilkhaire/gox/crypto

SHA256

Overview

SHA256 returns the SHA-256 digest of data as lowercase hex (crypto.createHash('sha256')).

If you are coming from Node.js, the closest pattern is crypto.createHash('sha256').update(d).digest('hex').

Signature

go
func SHA256(data []byte) string

Compare: Node.js · Standard Go · gox

js
crypto.createHash('sha256').update(data).digest('hex');
go
h := sha256.Sum256(data)
// or hmac.New(sha256.New, key)
go
import "github.com/sahilkhaire/gox/crypto"

got := SHA256([]byte("hello"))
want := "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
h := HMACSHA256([]byte("data"), []byte("key"))

Example

go
import "github.com/sahilkhaire/gox/crypto"

got := SHA256([]byte("hello"))
want := "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
h := HMACSHA256([]byte("data"), []byte("key"))

Tips

Import github.com/sahilkhaire/gox/crypto and call SHA256 directly. See the comparison below for the standard library equivalent.

Standard library alternative

Use the standard library directly:

go
h := sha256.Sum256(data)
// or hmac.New(sha256.New, key)

Back to crypto package overview

MIT Licensed · Built for Node.js developers moving to Go