mirror of
https://github.com/S2-/securerandomstring.git
synced 2025-08-02 02:10:05 +02:00
18 lines
330 B
JavaScript
18 lines
330 B
JavaScript
var crypto = require('crypto');
|
|
|
|
function securerandomstring(cb, options) {
|
|
options = options || {};
|
|
var length = options['length'] || 32;
|
|
|
|
crypto.randomBytes(length, function(ex, buf) {
|
|
if (ex) throw ex;
|
|
|
|
var string = buf.toString('base64');
|
|
cb(string.substr(0, length));
|
|
});
|
|
|
|
};
|
|
|
|
|
|
module.exports = securerandomstring;
|