Skip to content

Commit

Permalink
replace math.random() to crypto.randamBytes() on nodejs (AthenZ#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctyano authored and havetisyan committed May 23, 2018
1 parent 84a523b commit 532efa7
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions libs/nodejs/auth_core/src/util/Crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
var crypto = require('crypto');
var ybase64 = require('./YBase64');

var SALT_LENGTH = 8;
var SALT_CHARS = '0123456789abcdef';
var SALT_BYTES = 4;

class Crypto {
static hmac(message, sharedSecret) {
Expand Down Expand Up @@ -52,12 +51,8 @@ class Crypto {
}

static randomSalt() {
var c, i, salt = '';
for (c = 0; c < SALT_LENGTH; c++) {
i = Math.floor(Math.random() * SALT_CHARS.length);
salt += SALT_CHARS.charAt(i);
}
return salt;
var salt = crypto.randomBytes(SALT_BYTES);
return salt.toString('hex');
}
}

Expand Down

0 comments on commit 532efa7

Please sign in to comment.