打印散列值?
Printing out hashed values?
我试图打印出一个应用了 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;
}
});
Meteor.call() 没有 return 您期望的值;你需要检查回调。使用这样的东西:
Meteor.call('generateHash', function(error, hash) {
if (error) {
console.log(error);
} else {
console.log(hash);
}
});
我的问题是散列值的方式。首先,我确保将我的 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;
}
我试图打印出一个应用了 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;
}
});
Meteor.call() 没有 return 您期望的值;你需要检查回调。使用这样的东西:
Meteor.call('generateHash', function(error, hash) {
if (error) {
console.log(error);
} else {
console.log(hash);
}
});
我的问题是散列值的方式。首先,我确保将我的 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;
}