Skip to content

PKCS12 API

dweller long gone edited this page May 22, 2026 · 1 revision

PKCS#12 API

PKCS#12 helpers are exported from @pkistudio/pvkgadgets/pkcs12 for host applications that own their own UI.

import { readPkcs12Keys, writePkcs12Keys } from '@pkistudio/pvkgadgets/pkcs12';

The helpers are built on PKIjs and asn1js. They parse and write structured PKCS#12 data instead of manipulating ASN.1 bytes with ad hoc string logic.

Import

readPkcs12Keys reads .p12 or .pfx bytes and extracts key material where possible.

Supported import behavior includes:

  • password-protected PKCS#12 files.
  • private key extraction.
  • matching certificate extraction.
  • key-only PKCS#12 files without certificates.
  • friendly names and local key identifiers when available.

The browser app uses this helper when Open receives PKCS#12 input.

Export

writePkcs12Keys writes password-protected PKCS#12 data from selected key pairs.

Export behavior includes:

  • shrouded private key bags.
  • matching Certificate child items when present.
  • browser-friendly byte output that can be saved by the host.

The browser app uses this helper from the Save workflow.

Key and Certificate Shape

Private Key Gadgets keeps imported and generated data in DER form:

  • PKCS#8 DER for private keys.
  • SPKI DER for public keys.
  • X.509 certificate DER for certificates.

PKCS#12 imports that already include a certificate do not create a separate PublicKey child item in the browser app. The certificate public key is still used internally when matching is needed.

Clone this wiki locally