Dart
Dart
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 Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final mime = CkMime();
// Load a PFX file into a certificate object.
final cert = CkCert();
final pfxFilepath = 'pfxFiles/something.pfx';
final pfxPassword = 'secret';
try {
cert.loadPfxFile(pfxFilepath, pfxPassword);
} on ChilkatException catch (e) {
print(e.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);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Save the S/MIME to a file.
try {
mime.saveMime('/temp/signedMime.txt');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('success!');
}