3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 06:19:24 +01:00

Moved crypto module to internal node crypto api, removed (pretty) senseless cipher command and added random command

This commit is contained in:
amki 2015-04-25 04:06:01 +02:00
parent 15de4c4f5d
commit 79dd53e4c4
3 changed files with 33 additions and 31 deletions

View File

@ -14,7 +14,7 @@ then
exit 1
fi
npm install googlemaps feedparser node-units tvdb crypto-js method-override 500px process async wordnik node-uuid underscore request sandbox express moment-timezone moment jade databank databank-redis ent passport passport-local password-hash connect-flash
npm install googlemaps feedparser node-units tvdb method-override 500px process async wordnik node-uuid underscore request sandbox express moment-timezone moment jade databank databank-redis ent passport passport-local password-hash connect-flash
cd public/
wget https://github.com/twbs/bootstrap/releases/download/v3.3.2/bootstrap-3.3.2-dist.zip

View File

@ -7,15 +7,9 @@ This module calculates different hashes or ciphertexts for some algorithms.
### Commands
#### ~md5 [text]
Calculate the MD5 hash of the given text.
#### ~hash [algorithm] [text]
Calculate the hash of the given text using [algorithm].
#### ~sha1 [text]
Calculate the SHA1 hash of the given text.
#### ~sha256 [text]
Calculate the SHA256 hash of the given text.
#### ~aes "[text]" "[key]"
Calculates the hash of the given text.
#### ~random [number]
Gives [number] bytes of cryptographically strong pseudo-random data as hex string.

View File

@ -3,32 +3,40 @@
* Description: Allows the magic of cryptography to take place.
*/
var MD5 = require('crypto-js/md5');
var SHA1 = require('crypto-js/sha1');
var SHA256 = require('crypto-js/sha256');
var SHA512 = require('crypto-js/sha512');
var AES = require('crypto-js/aes');
var cr = require('crypto');
var crypto = function(dbot) {
this.commands = {
'~md5': function(event) {
event.reply("MD5 hash of "+event.input[1]+" is: "+MD5(event.input[1]));
'~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);
}
},
'~sha1': function(event) {
event.reply("SHA1 hash of "+event.input[1]+" is: "+SHA1(event.input[1]));
},
'~sha256': function(event) {
event.reply("SHA256 hash of "+event.input[1]+" is: "+SHA256(event.input[1]));
},
'~aes': function(event) {
event.reply("AES of "+event.input[1]+" is: "+AES.encrypt(event.input[1],event.input[2]));
'~random': function(event) {
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);
}
}
};
this.commands['~md5'].regex = /^md5 ([^ ]+)$/;
this.commands['~sha1'].regex = /^sha1 ([^ ]+)$/;
this.commands['~sha256'].regex = /^sha256 ([^ ]+)$/;
this.commands['~aes'].regex = /^aes "(.*)" "(.*)"$/;
};
exports.fetch = function(dbot) {