Sample code for 30+ languages & platforms
React Native

Add S/MIME Signature using PFX

See more MIME Examples

Add a digital signature to a MIME message using the certificate + private key from a PFX file.

Chilkat React Native Downloads

React Native
import { Cert, Mime } from '@chilkat/react-native'

function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const mime = new Mime();

  // Load a PFX file into a certificate object.
  const cert = new Cert();
  const pfxFilepath = 'pfxFiles/something.pfx';
  const pfxPassword = 'secret';
  try {
    cert.loadPfxFile(pfxFilepath, pfxPassword);
  } catch {
    console.log(cert.lastErrorText);
    return;
  }

  mime.setBodyFromPlainText('This is the plain-text MIME body.');

  mime.charset = 'utf-8';
  mime.encoding = 'quoted-printable';

  // Sign the MIME (adds a PKCS7 detached signature)
  try {
    mime.addDetachedSignature(cert);
  } catch {
    console.log(mime.lastErrorText);
    return;
  }

  // Save the S/MIME to a file.
  try {
    mime.saveMime('/temp/signedMime.txt');
  } catch {
    console.log(mime.lastErrorText);
    return;
  }

  console.log('success!');
}