Using crypto instead of URSA in Node

Added by Joachim 10 months ago

Hi,

Since URSA is not working from Node 10 and onwards. Has anyone managed to change the encryptLogin to using crypto or any other supported library?

I tried with this

function encryptLogin(user, pass, keyfile) {
  var rsaPublic = fs.readFileSync(keyfile, 'ascii');
  //var key = ursa.createPublicKey(rsaPublic, 'utf8');

  if (!key) {
    console.log('KEY error');
  }

  var auth = new Buffer(user).toString('base64');
  auth += ':';
  auth += new Buffer(pass).toString('base64');
  auth += ':';
  auth += new Buffer('' + new Date().getTime()).toString('base64');

  var buffer = new Buffer(auth);
  var key = crypto.publicEncrypt(Buffer.from(rsaPublic), buffer);

  return key.toString('base64');
  //return key.encrypt(auth, 'utf8', 'base64', ursa.RSA_PKCS1_PADDING);
}


Replies (1)

RE: Using crypto instead of URSA in Node - Added by Claes 8 months ago

Yes , I have created a modified version of the wiki sample script for logging in and subscribing.
The sample is using crypto. The key is to define padding ( crypto.constants.RSA_PKCS1_PADDING ) , to make it work.

var key_data = {
        key: publicKey,
        padding: crypto.constants.RSA_PKCS1_PADDING
    };

I created a git repo for it just in case I might add additional nordnet related stuff.

Look under https://github.com/slaskhas/nordnet-stuff

(1-1/1)