1

I am trying to create hash key in node js. For this I installed sha512 plugin using

npm install sha512

And I tried the below code:

var sha512 = require('sha512');
var marchentKey = 'gtKFFx';// 'gtKFFx';//'96s2Ls';
var salt = 'eCwWELxi';// 'eCwWELxi';//'J9GhS9hs';
res.header('Access-Control-Allow-Origin', '*');
res.setHeader('Content-Type', 'application/json');
var params = req.swagger.params;
var token = params.token.value || null;
var firstname = params.firstname.value || null;
var phone = params.phone.value || null;
var email = params.email.value || null;
var amount = params.amount.value || null;
var productinfo = params.productinfo.value || null;
var udf1 = 'Test Value1';
var udf2 = 'Test Value2';
var udf3 = 'Test Value3';
var udf4 = 'Test Value4';
var udf5 = 'Test Value5';
var surl = params.surl.value || null;
var furl = params.furl.value || null;
MongoClient.connect(url, function (err, db) {
    db.collection('user').findOne({'token': token}, function (err, docs) {
        if (docs) {
            require('crypto').randomBytes(6, function (err, buffer) {
                var txnid = buffer.toString('hex').toUpperCase();
                var string = marchentKey + '|' + txnid + '|' + amount + '|' + productinfo + '|' + firstname + '|' + email + '|' + udf1 + '|' + udf2 + '|||||||||' + salt;
                var hash = sha512(string);
                db.close();
                res.send(JSON.stringify({status: true, hash: hash, txnid: txnid, message: 'Hash Key Result'}));
            })
        } else {
            db.close();
            res.send(JSON.stringify({status: false, hash: hash, message: 'Invalid Token'}));
        }
    })
})

It is giving me error that you should use the sequence for creating hash that I am using here -

marchentKey + '|' + txnid + '|' + amount + '|' + productinfo + '|' + firstname + '|' + email + '|' + udf1 + '|' + udf2 + '|||||||||' + salt;

How do I do this?

4

0 回答 0