ImportCertificate Method
Imports a certificate from a file into the current certificate store.
Syntax
certmgr.importCertificate(certFile, password, subject, [callback])
Callback
The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).
The callback for this method is defined as:
function(err){ }
'err' is the error that occurred. If there was no error, then 'err' is 'null'.
'err' has 2 properties which hold detailed information:
err.code err.message
Remarks
This method will import a certificate from a file into the current certificate store.
On Windows platforms certificates may only be imported to the Windows certificate store. To load a certificate without importing it to a Windows store set Cert*.
Certificate files with or without a private key may be imported. If the file specified CertFile contains a private key the private key will be imported along with the public certificate. If the file specified by CertFile contains only a public certificate, only the public certificate will be imported.
The Password parameter specifies the certificate password (if any). When importing a public certificate set Password to empty string.
The format of the certificate file being imported must contain valid X509 data to be imported. Not all certificate file formats include X509 data such as PPK or PKCS8 private keys. If the CertFile is of a format that cannot be imported the class fails with an error.
Note: On Linux based operating system this method loads the specified certificate without importing into any system location.
Subject is optional. If empty, the first certificate in the store is loaded instead of the matching certificate.
ImportCertificate Example
//Import a PFX
certmgr.ImportCertificate("..\\test.pfx", "password", "*");
//Import a public certificate (CER)
certmgr.ImportCertificate("..\\test.cer", "", "*");