Skip to content
DemoAPI ReferenceFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub
React Native Guides Certificate management

Certificate Management ​

Before signing a PDF, prepare a PKCS#12 file (.p12 or .pfx) containing the private key and its password. The following static methods are provided by ComPDFKit. Initialize the SDK license before using them.

Generate a Certificate ​

ts
import { ComPDFKit, CPDFCertificateUsage }
  from '@compdfkit_pdf_sdk/react_native';

async function createCertificate(outputPath: string, password: string) {
  const success = await ComPDFKit.generatePkcs12Certificate({
    subject: { commonName: 'Document Signer',
      organization: 'Example Company', country: 'CN' },
    password, outputPath,
    usage: CPDFCertificateUsage.DIGITAL_SIGNATURE,
  });
  if (!success) throw new Error('Failed to generate the certificate');
}

commonName, a nonempty password, and an output path are required. The parent directory must exist and be writable. Optional subject fields include state, locality, organizationalUnit, and email. usage accepts DIGITAL_SIGNATURE, DATA_ENCRYPTION, or ALL, and defaults to digital signing.

Generated certificates are suitable for testing or application-managed signing workflows. If recipients require a recognized identity, use a certificate issued by a trusted authority according to your business requirements.

Check the Password and Read Information ​

ts
import { ComPDFKit } from '@compdfkit_pdf_sdk/react_native';

async function readCertificate(path: string, password: string) {
  if (!await ComPDFKit.checkPkcs12CertificatePassword(path, password)) {
    throw new Error('Certificate password verification failed');
  }
  const info = await ComPDFKit.loadPkcs12Certificate(path, password);
  if (info === null) throw new Error('Failed to read the certificate');
  return info;
}

The returned CPDFCertificateInfo includes the subject, issuer, validity period, serial number, key type, signature algorithm, digests, isTrusted, and isExpired. Some information may be unavailable; handle optional fields accordingly. Do not log certificate passwords or private keys.

Add a Trusted Certificate ​

ts
import { ComPDFKit } from '@compdfkit_pdf_sdk/react_native';

async function trustCertificate(certificatePath: string, password: string) {
  const success = await ComPDFKit.addTrustedCertificate(certificatePath, password);
  if (!success) throw new Error('Failed to add the trusted certificate');
}

Provide an accessible local PKCS#12 path and its password. This affects verification trust within the application's SDK; it does not make other devices or recipients trust the certificate automatically. Methods may return false or null, or reject the Promise. Handle each result appropriately.