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

HMACSHA256

Overview

HMACSHA256 returns HMAC-SHA256 of data with key as lowercase hex.

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

Signature

go
func HMACSHA256(data, key []byte) string

Compare: Node.js · Standard Go · gox

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

crypto.HMACSHA256(d, key)

Example

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

crypto.HMACSHA256(d, key)

Tips

Import github.com/sahilkhaire/gox/crypto and call HMACSHA256 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