-2

How to get .pfx file from .cer and .key in NodeJS?

class SAT {
    constructor() {
        this.options = {
            wsdl_options: {
                pfx: {
                    cer: fs.readFileSync(publicKeyPath),
                    key: fs.readFileSync(privateKeyPath)
                }
            },
            passphrase: PASSWORD_PKEY
        }
    }

1 Answers1

0

You can use the chilkat library. The pfx library is free. Load the appropriate library found at https://www.chilkatsoft.com/nodejs.asp:

var os = require('os');
if (os.platform() == 'win32') {  
   var chilkat = require('chilkat_node10_win32'); 
} else if (os.platform() == 'linux') {
   if (os.arch() == 'arm') {
      var chilkat = require('chilkat_node10_arm');
   } else if (os.arch() == 'x86') {
       var chilkat = require('chilkat_node10_linux32');
   } else {
       var chilkat = require('chilkat_node10_linux64');
   }
  } else if (os.platform() == 'darwin') {
     var chilkat = require('chilkat_node10_macosx');
}

Use the following code to produce a Pfx File:

var pfx = new chilkat.Pfx();
var privKey = new chilkat.PrivateKey();
var cert = new chilkat.Cert();

cert.LoadFromFile(publicKeyPath);
privKey.LoadPemFile(privateKeyPath, PASSWORD_PKEY);
pfx.AddPrivateKey(privKey,certChain);
pfx.ToFile("pfxPassword","sample.pfx");