React Native
React Native
Set the Decryption Certificate and Private Key
See more POP3 Examples
Demonstrates the Chilkat MailMan.SetDecryptCert2 method, which explicitly specifies both the certificate and its associated private key, as separate objects, to use when decrypting S/MIME encrypted email. This example loads a .cer certificate and a PEM private key, registers both, and fetches a message Chilkat can decrypt.
Background: Credentials are not always packaged together. When the certificate is a standalone
.cer and the private key is a separate PEM (or other) file, SetDecryptCert2 takes the two objects individually. It is the two-object counterpart to SetDecryptCert, which expects a single certificate that already carries its private key (such as one loaded from a PFX).Chilkat React Native Downloads
import { Cert, Email, MailMan, PrivateKey } from '@chilkat/react-native'
async function chilkatExample() {
// Demonstrates the MailMan.SetDecryptCert2 method, which explicitly specifies both the
// certificate and its associated private key (as separate objects) to use when decrypting
// S/MIME encrypted email.
const mailman = new MailMan();
// Configure the POP3 server connection.
mailman.mailHost = 'pop.example.com';
mailman.mailPort = 995;
mailman.popSsl = true;
mailman.popUsername = 'user@example.com';
mailman.popPassword = 'myPassword';
// Load the certificate (public) and the matching private key from separate files.
const cert = new Cert();
try {
cert.loadFromFile('qa_data/certs/recipient.cer');
} catch {
console.log(cert.lastErrorText);
return;
}
const privKey = new PrivateKey();
try {
privKey.loadPemFile('qa_data/certs/recipient_privkey.pem');
} catch {
console.log(privKey.lastErrorText);
return;
}
// Specify the certificate and private key to use when decrypting downloaded email.
try {
mailman.setDecryptCert2(cert, privKey);
} catch {
console.log(mailman.lastErrorText);
return;
}
// Fetch a message; if it is encrypted, Chilkat decrypts it using the certificate and key.
const email = new Email();
try {
await mailman.fetchOneAsync(false, 0, 1, email);
} catch {
console.log(mailman.lastErrorText);
return;
}
console.log(`Decrypted = ${email.decrypted}`);
// Note: Paths such as "qa_data/..." are relative local filesystem paths,
// relative to the current working directory of the running application.
// Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
// connects and authenticates -- using the property settings above -- whenever a server
// operation requires it. Calling the explicit connect/authenticate methods can still be
// helpful to determine whether a failure occurs while connecting or while authenticating.
}