2013-12-26 07:44:13 +01:00
|
|
|
/**
|
2013-12-26 07:59:56 +01:00
|
|
|
* Module Name: Crypto
|
|
|
|
* Description: Allows the magic of cryptography to take place.
|
2013-12-26 07:44:13 +01:00
|
|
|
*/
|
|
|
|
|
2015-04-25 04:06:01 +02:00
|
|
|
var cr = require('crypto');
|
2013-12-26 07:44:13 +01:00
|
|
|
|
|
|
|
var crypto = function(dbot) {
|
|
|
|
this.commands = {
|
2015-04-25 04:06:01 +02:00
|
|
|
'~hash': function(event) {
|
|
|
|
var hash = event.params[1];
|
|
|
|
try {
|
|
|
|
var h = cr.createHash(hash);
|
|
|
|
var tohash = event.params.splice(2, event.params.length-1).join(' ');
|
|
|
|
h.update(tohash);
|
|
|
|
event.reply(hash+" of \""+tohash+"\" is: "+h.digest('hex'));
|
|
|
|
} catch(err) {
|
|
|
|
event.reply(err);
|
|
|
|
}
|
2013-12-26 07:44:13 +01:00
|
|
|
},
|
2015-08-19 21:11:33 +02:00
|
|
|
'~randomdata': function(event) {
|
2015-04-25 04:06:01 +02:00
|
|
|
try {
|
|
|
|
var count = parseInt(event.params[1]);
|
|
|
|
if(count > 222) {
|
|
|
|
event.reply("Sorry man, I can't paste that much random data.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cr.randomBytes(count, function(err,buf) {
|
|
|
|
if(err) {
|
|
|
|
event.reply(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.reply(buf.toString('hex'));
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
event.reply(err);
|
|
|
|
}
|
2013-12-26 07:44:13 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return new crypto(dbot);
|
|
|
|
};
|