Browse Source

use SecureRandom in Key in the browser

...to make sure random numbers are generated securely
patch-2
Ryan X. Charles 11 years ago
parent
commit
dbcf270826
  1. 13
      lib/browser/Key.js

13
lib/browser/Key.js

@ -1,5 +1,6 @@
var ECKey = require('../../browser/vendor-bundle.js').ECKey;
var buffertools = require('buffertools');
var SecureRandom = require('../SecureRandom');
var Key = function() {
this._pub = null;
@ -33,13 +34,17 @@ Object.defineProperty(Key.prototype, 'public', {
});
Key.generateSync = function() {
var eck = new ECKey();
var privbuf = SecureRandom.getRandomBuffer(32);
var privhex = privbuf.toString('hex');
var eck = new ECKey(privhex);
eck.setCompressed(true);
var pub = eck.getPub();
var ret = new Key();
ret.private = new Buffer(eck.priv.toByteArrayUnsigned());
ret.public = new Buffer(pub);
ret = new Key();
ret.private = privbuf;
ret.compressed = true;
ret.public = new Buffer(eck.getPub());
return ret;
};

Loading…
Cancel
Save