Using crypto instead of URSA in Node

Added by Joachim 29 days ago


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