ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Mircryption

mircryption for NodeJS

(1/2) > >>

McDeffice:
I would like to use mircryption with NodeJS, I did not find anything about it.

Can you help me with my quests? tks

mouser:
It's an interesting question.. I have been doing quite a bit of nodejs coding myself lately.
But I don't know of any nodejs code out of the box that can do mircryption.

However, the encryption and decryption are basically just the blowfish algorithm, running in ecb and cbc mode.  So that's the javascript code you'd want to hunt for.

McDeffice:
i would like to use to encrypt and decrypt IRC messages via an IRC bot in NodeJS. This message uses CBC or ECB blowfish mircryption using block and base64 encryption.

I find information here:

--- ---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.
Source : IRC blowfish encryption mode?
- Block_cipher_mode_of_operation
- Java Code example

what I found closest to javascript is here:
- javascript-blowfish package
- egoroof-blowfish package

tks!

EDIT :
The data transmitted by FiSH is not standard Base64. It uses a nonstandard encoding table which you'll have to account for.


McDeffice:
My test CBC MODE


--- ---// 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));

No one is interested in the topic? Any help is welcome ! tks

mouser:
I'm interested in hearing about your progress! Keep going!

Navigation

[0] Message Index

[#] Next page

Go to full version