0

I need to create hash using the hmac sha256 in react native, so far does not have any suitable library that give the same expected result. this is the code that I use in node.js:

var crypto = require('crypto');

            hashMessage = 'hello';
            secretKey = '123456asdf';

            var hmac = crypto.createHmac('sha256', secretKey);
            
            strmessage = hashMessage+secretKey;
            data = hmac.update(strmessage);
            
            gen_hmac = data.digest('hex');

            return gen_hmac;

the code I use in react native using crypto-js:

secretKey = '123456asdf';
        var hash = CryptoJS.HmacSHA256(hashMessage, secretKey);
        hash = hash.toString();

this is the expected result which is from the node js:

ed467adaf9d9c07506d6d96281ff069e78dc1e72ba3c2fcdc785de22bb9285d0

this is the one I get using the one in react native:

1807ea9c32e064f4426615948999bfc0f0e2bceb6de282f5bdb06d74092e37bf

any suggestion to library or method I can use to get the same expected result from the one in node js? really need help

Vyron
  • 1

0 Answers0