打印出散列值?

时间:2016-01-06 03:31:45

标签: javascript meteor hashcode

我正在尝试打印出一个我应用sha256哈希的int,但我只在服务器日志中获取[object Object]。

有关如何打印/查看对象的任何想法?

Meteor.methods({
twilioTest:function () {

console.log("Twilio Test Called!");

    // Get time for 2fa code
    var d = new Date();
    var seconds = d.getTime() / 1000;
    seconds = parseInt(seconds);

    // Get large random int
    var largeInt = Math.floor(Math.random() * (999999999 - 99999999999999999) + 99999999999999999);

    console.log("seconds value: " + seconds);
    console.log("largeInt value: " + largeInt);

    // Combine the values
    var combined = seconds + largeInt;

    console.log("combined value: " + combined);

    // Hash the value
    combined = Meteor.call('generateHash',combined);
    console.log("combined value HASHED: " + combined);

},

generateHash: function(val){
    check(val, Match.Any);
    var hash = 0;

    var crypto = Npm.require('crypto');
    var key = 'abc123';

    hash = crypto.createHmac('sha256', key);

    return hash;
}
});

2 个答案:

答案 0 :(得分:0)

Meteor.call()不会以您期望的方式返回值;你需要检查回调。使用这样的东西:

$searchword = 'last';
$matches = array();
foreach($example as $k=>$v) {
    if(preg_match("/\b$searchword\b/i", $v)) {
        $matches[$k] = $v;
    }
}

答案 1 :(得分:0)

我的问题是我挖掘价值的方式。首先,我确保将我的int类型转换为字符串,然后这就是应该如何生成散列:

generateHash: function(val){
    check(val, Match.Any);
    var hash = 0;

    var crypto = Npm.require('crypto');
    var key = 'abc123';

    hash = crypto.createHmac('sha256', key).update(val).digest('hex') // This line is key

    return hash;
}