Skip to content

crypto.privateDecrypt cannot decrypt message #22792

Closed
@Nolaan

Description

@Nolaan
  • Version: v8.11.3
  • Platform: Linux x86_64
  • Subsystem:

I'm trying to encrypt/decrypt data using a rsa key but the process fails somehow with this message :

Error: error:04099079:rsa routines:RSA_padding_check_PKCS1_OAEP_mgf1:oaep decoding error

Code :

var  childProcess = require('child_process');
var  crypto = require('crypto');

var pk;
var mess_chiffre;

var sign = function () {
  var buf = new Buffer("Coucou c'est relou!!!");
  var sig = crypto.privateEncrypt(pk,buf);
  mess_chiffre = sig.toString('hex');
  console.log("Signed : ", mess_chiffre);
};


var decrypt = function () {
  var buff = new Buffer(mess_chiffre,'hex')
  console.log('Buffer : ',buff)
  console.log('decrypting withh pk: ')
  console.log(pk)
  var mess = crypto.privateDecrypt(pk,buff)
  console.log(mess)
};


childProcess.exec('openssl rsa -in private.key', {},
    function (err, stdout, stderr) {
  if (err) throw err;
  pk = stdout; // Save in memory for later use
  sign();
  decrypt();
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    cryptoIssues and PRs related to the crypto subsystem.docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions