I would like to use mircryption with NodeJS, I did not find anything about it.
Can you help me with my quests? tks
Can you help me with my quests? tks


Blowfish plugins for IRC seem to use the MODE_ECB (electronic code book), which is probably the least secure of the blowfish algorithms.
For encryption, they break the plaintext up into 8-byte chunks (the Blowfish ECB blocksize). They then encrypt each 8-byte block separately, and take the output of each encrypted block, and chunk that into (2) 4-byte longs, and base64encode each long, padding them to length of 6 base64 characters.
For decryption, this process is reversed, but because it's somewhat confusing I'll also describe that. Take 12 of the ciphertext bytes, decoding each 6-byte representation as a long ('>L'), so that you now have 8 bytes, which you then pass to the blowfish decryption algo.
// Blowfish CBC code
const Blowfish = require('egoroof-blowfish');
const ircPrefix = "+OK *";
const IV = '00000000';
function generateIV() {
const left = Math.random().toString(36).substring(2, 6);
const right = Math.random().toString(36).substring(2, 6);
return left + right;
}
function encode(str) {
const textToEncode = generateIV() + str;
const encodedString = Buffer.from(blowfish.encode(textToEncode)).toString('base64');
return ircPrefix + encodedString;
}
function decode(str) {
const cleanText = str.substring(ircPrefix.length)
const data = Buffer.from(cleanText, 'base64');
const decoded = blowfish.decode(data, Blowfish.TYPE.UINT8_ARRAY);
const decrypt = Buffer.from(decoded).slice(8).toString('utf8');
return decrypt;
}
var test_key = 'test123';
const blowfish = new Blowfish(test_key, Blowfish.MODE.CBC, Blowfish.PADDING.PKCS5);
blowfish.setIv(IV);
// Testing code
var test_text = 'test';
console.log('text: ' + test_text);
const encoded = encode(test_text);
console.log('encoded: ' + encoded);
console.log('decoded: ' + decode(encoded)); 
Original address: https://www.donationcoder.com/forum/index.php?topic=49725.0