177
rated 0 times
[
182]
[
5]
/ answers: 1 / hits: 42948
/ 11 Years ago, fri, november 29, 2013, 12:00:00
I need a random sequence of bytes for making a password hash. In Ruby, this would look like:
File.open(/dev/urandom).read(20).each_byte{|x| rand << sprintf(%02x,x)}
In Node.js, I can get a sequence of random bytes with:
var randomSource = RandBytes.urandom.getInstance();
var bytes = randomSource.getRandomBytesAsync(20);
But the problem is, how to convert these to a String?
Also, I need to have them wrapped in promisses. Would this work:
get_rand()
.then(function(bytes) {
authToken = bytes;
})
More From » node.js