topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday November 9, 2024, 7:18 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: mircryption for NodeJS  (Read 13017 times)

McDeffice

  • Participant
  • Joined in 2020
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
mircryption for NodeJS
« on: March 28, 2020, 02:11 PM »
I would like to use mircryption with NodeJS, I did not find anything about it.

Can you help me with my quests? tks

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,913
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: mircryption for NodeJS
« Reply #1 on: March 31, 2020, 12:15 PM »
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

  • Participant
  • Joined in 2020
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Re: mircryption for NodeJS
« Reply #2 on: March 31, 2020, 12:35 PM »
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.


« Last Edit: March 31, 2020, 12:42 PM by McDeffice »

McDeffice

  • Participant
  • Joined in 2020
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Re: mircryption for NodeJS
« Reply #3 on: April 04, 2020, 01:51 PM »
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

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,913
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: mircryption for NodeJS
« Reply #4 on: April 04, 2020, 01:52 PM »
I'm interested in hearing about your progress! Keep going!

McDeffice

  • Participant
  • Joined in 2020
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Re: mircryption for NodeJS
« Reply #5 on: May 25, 2020, 02:54 PM »
up

silv3r

  • Participant
  • Joined in 2020
  • *
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
Re: mircryption for NodeJS
« Reply #6 on: August 18, 2020, 03:33 AM »
Interesting indeed.

New to nodejs and couldnt figure it out either, same as OP.
Could not find a working module either.

I tried default nodejs crypto but couldnt get the padding to work iirc.
Remember using that 'non-standard encoding table' var instead of normal b64 isnt enough.

Also tried:

- base convertor: https://stackoverflow.com/q/7122417
- https://gist.github....atnickcodes/11257943
- sladex-blowfish (http://sladex.org/blowfish.js)
- dojo-release-1.8.1/dojox/encoding/crypto/_base.js.uncompressed.js
- javascript-blowfish/Blowfish.node.js


Ended up just writing a wrapper around blowssi and calling that with childProcess.execSync on message, pm and notice listeners (from nodejs-irc)
It does both chan and DH1080 keyx in cbc and ebc modes.
Its a bit slow but hey it works.