Extract PEM-encoded keys and certificates from PKCS#12 bundles
Lightweight ESM utility for converting PKCS#12 bundles into a private key, certificate, and certificate common name. The root export preserves the Node.js file helper, and the browser-safe converter is exposed on a dedicated subpath.
Generate the API documentation locally with:
npm run docnpm install @tak-ps/node-p12import { getPemFromP12 } from '@tak-ps/node-p12';
const { pemKey, pemCertificate, commonName } = getPemFromP12('./client.p12', 'password');
console.log(commonName);
console.log(pemKey);
console.log(pemCertificate);import { convertToPem } from '@tak-ps/node-p12/browser';
const response = await fetch('/client.p12');
const buffer = await response.arrayBuffer();
const { pemKey, pemCertificate, commonName } = convertToPem(buffer, 'password');
console.log(commonName);
console.log(pemKey);
console.log(pemCertificate);Available from @tak-ps/node-p12/browser. Converts PKCS#12 data from a string, ArrayBuffer, or Uint8Array and returns:
pemKey: the private key in PEM formatpemCertificate: the certificate in PEM formatcommonName: the certificate subject common name
Node-only helper, available from @tak-ps/node-p12 and @tak-ps/node-p12/node, that reads a PKCS#12 bundle from disk and returns:
pemKey: the private key in PEM formatpemCertificate: the certificate in PEM formatcommonName: the certificate subject common name