What is google-p12-pem?
The google-p12-pem npm package is used to convert Google .p12 or PFX files to the PEM format. This is particularly useful when dealing with authentication in Google Cloud Platform services, as it allows developers to transform the private key obtained from Google into a format that can be used with various authentication libraries.
What are google-p12-pem's main functionalities?
Convert P12 to PEM
This feature allows you to convert a .p12 or PFX file to PEM format. The code sample demonstrates how to use the `getPem` function provided by the package to perform the conversion. The function takes the path to the .p12 file and a callback function that receives an error or the resulting PEM.
const { getPem } = require('google-p12-pem');
getPem('/path/to/key.p12', (err, pem) => {
if (err) {
console.error('Error converting P12 to PEM', err);
return;
}
console.log(pem);
});
Convert P12 to PEM with Promise
This feature is similar to the previous one but uses Promises instead of callbacks. It allows for better integration with modern asynchronous JavaScript code, such as async/await syntax.
const { getPem } = require('google-p12-pem');
getPem('/path/to/key.p12').then(pem => {
console.log(pem);
}).catch(err => {
console.error('Error converting P12 to PEM', err);
});
Other packages similar to google-p12-pem
node-forge
node-forge is a JavaScript implementation of various network security protocols. It includes functionality for creating, converting, and managing private keys and certificates in different formats, including PEM. It is more comprehensive than google-p12-pem, as it covers a wider range of cryptographic operations.
pem
pem is an npm package that provides a set of tools for managing and creating SSL certificates and keys. It can create private keys and CSRs, create certificates, read certificates, and more. It is similar to google-p12-pem in that it can handle PEM files, but it offers a broader set of features related to certificate management.
google-p12-pem
Convert Google .p12
keys to .pem
keys.
Installation
npm install google-p12-pem
Usage
Asynchronous
var gp12 = require('google-p12-pem');
gp12('/path/to/key.p12', function(err, pem) {
if (err) {
console.log(err);
} else {
console.log(pem);
}
});
Synchronous
Note: If an error occurs and the callback is omitted, it will throw the error.
var gp12 = require('google-p12-pem');
var pem = gp12('/path/to/key.p12');
console.log(pem);
CLI
gp12-pem myfile.p12 > output.pem
License
MIT