2012-01-07 16:35:11 +00:00
|
|
|
var RandomKeyGenerator = function(options) {
|
2012-01-13 16:16:42 +00:00
|
|
|
if (!options) {
|
|
|
|
options = {};
|
|
|
|
}
|
2012-01-07 16:35:11 +00:00
|
|
|
this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
};
|
|
|
|
|
|
|
|
// Generate a random key
|
|
|
|
RandomKeyGenerator.prototype.createKey = function(keyLength) {
|
|
|
|
var text = '';
|
|
|
|
for (var i = 0; i < keyLength; i++) {
|
|
|
|
text += this.keyspace.charAt(Math.floor(Math.random() * this.keyspace.length));
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = RandomKeyGenerator;
|