Nodejs snippet: HMAC-MD5 HMAC-SHA1 HMAC-SHA256


HMAC-MD5

   import { createHmac } from 'crypto'
    //const createHmac = require('crypto').createHmac
    function hmacmd5(string, secret = '123456'){                
        const hash = createHmac('md5',secret)
                        .update(string+"")
                        .digest('hex');        
        return hash
    }

HMAC-SHA1

   import { createHmac } from 'crypto'
    //const createHmac = require('crypto').createHmac
    function hmacsha1(string, secret = '123456'){                
        const hash = createHmac('sha1',secret)
                        .update(string+"")
                        .digest('hex');        
        return hash
    }

HMAC-SHA256

   import { createHmac } from 'crypto'
    //const createHmac = require('crypto').createHmac
    function hmacsha256(string, secret = '123456'){                
        const hash = createHmac('sha256',secret)
                        .update(string+"")
                        .digest('hex');        
        return hash
    }

Leave a Reply