Merge pull request #648 from amki/crypto

Moved crypto module to internal node crypto api, remove ciphers, add random
This commit is contained in:
Luke Slater 2015-04-25 21:05:17 +03:00
commit 06f6491d99
3 changed files with 33 additions and 31 deletions

View File

@ -14,7 +14,7 @@ then
exit 1 exit 1
fi 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/ cd public/
wget https://github.com/twbs/bootstrap/releases/download/v3.3.2/bootstrap-3.3.2-dist.zip 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 ### Commands
#### ~md5 [text] #### ~hash [algorithm] [text]
Calculate the MD5 hash of the given text. Calculate the hash of the given text using [algorithm].
#### ~sha1 [text] #### ~random [number]
Calculate the SHA1 hash of the given text. Gives [number] bytes of cryptographically strong pseudo-random data as hex string.
#### ~sha256 [text]
Calculate the SHA256 hash of the given text.
#### ~aes "[text]" "[key]"
Calculates the hash of the given text.

View File

@ -3,32 +3,40 @@
* Description: Allows the magic of cryptography to take place. * Description: Allows the magic of cryptography to take place.
*/ */
var MD5 = require('crypto-js/md5'); var cr = require('crypto');
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 crypto = function(dbot) { var crypto = function(dbot) {
this.commands = { this.commands = {
'~md5': function(event) { '~hash': function(event) {
event.reply("MD5 hash of "+event.input[1]+" is: "+MD5(event.input[1])); 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) { '~random': function(event) {
event.reply("SHA1 hash of "+event.input[1]+" is: "+SHA1(event.input[1])); try {
}, var count = parseInt(event.params[1]);
'~sha256': function(event) { if(count > 222) {
event.reply("SHA256 hash of "+event.input[1]+" is: "+SHA256(event.input[1])); event.reply("Sorry man, I can't paste that much random data.");
}, return;
'~aes': function(event) { }
event.reply("AES of "+event.input[1]+" is: "+AES.encrypt(event.input[1],event.input[2])); 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) { exports.fetch = function(dbot) {