How do I use Node.js Crypto to create a HMAC-SHA1 hash?

user847495 picture user847495 · Sep 20, 2011 · Viewed 119.9k times · Source

I want to create a hash of I love cupcakes (signed with the key abcdeg)

How can I create that hash, using Node.js Crypto?

Answer

Ricardo Tomasi picture Ricardo Tomasi · Sep 20, 2011

Documentation for crypto: http://nodejs.org/api/crypto.html

const crypto = require('crypto')

const text = 'I love cupcakes'
const key = 'abcdeg'

crypto.createHmac('sha1', key)
  .update(text)
  .digest('hex')