How to generate an RSA key using openssl-wrapper in NodeJS?

1.6k views Asked by At

I am using openssl-wrapper, a nodejs package. It is easy to customize parameters! But i got an error, i can not make the code works properly.

The implemented code:

Q.fcall(function caKey() {
  var params = {
    des3: true,
    passout: 'pass:1234567890',
    out: key,
    '1024': false
  };
  console.log("caKey", dataFolder, params);
  return openssl.qExec('genrsa', params);
}).then(function debugOutput(data) {
    // onFullfill
    console.log("done", data);
  })
  .catch(function (err) {
    // get err
    console.error(err);
  });

I got this error:

caKey D:/certs-dev { '1024': false,
  des3: true,
  passout: 'pass:1234567890',
  out: 'D:/certs-dev/ca/ca.key' }
Wed, 27 Apr 2016 11:40:24 GMT openssl-wrapper > openssl genrsa -des3 -passout pass:1234567890 -out D:/certs-dev/ca/ca.key 1024
15316:error:02001000:system library:fopen:system library:bss_file.c:175:fopen('','rb')
15316:error:2006D002:BIO routines:BIO_new_file:system lib:bss_file.c:180:
15316:error:0E078002:configuration file routines:DEF_LOAD:system lib:conf_def.c:197:

What am i missing ? How can i make it works ?

Please help me. Thank you very much !

1

There are 1 answers

0
Vunb On BEST ANSWER

Thanks to @jww

Follow his guide, the error is resolved by configuring the environment variable:

set OPENSSL_CONF=c:\OpenSSL-Win32\bin\openssl.cfg

Or set the environment variable in NodeJS application, before call the function.

process.env.OPENSSL_CONF = "c:\OpenSSL-Win32\bin\openssl.cfg"