Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.0.0+

Sign an EML using RSA-PSS and SHA-256

See more Email Object Examples

Load the intended signing certificate and its RSA private key from a PFX. Set the signature options on Email and render the final S/MIME message through MailMan. The resulting multipart/signed file can be verified independently. Supply the PFX password through your application’s credential store.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // Assumes Chilkat is unlocked. See Global Unlock Sample.

  final email = CkEmail();
  try {
    email.loadEml('message.eml');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final cert = CkCert();
  try {
    cert.loadPfxFile('signer.pfx', 'PFX_PASSWORD');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  try {
    email.setSigningCert(cert);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  email.signingAlg = 'pss';
  email.signingHashAlg = 'sha256';
  email.sendSigned = true;
  final mail = CkMailMan();
  mail.opaqueSigning = false;
  final rendered = CkBinData();
  try {
    mail.renderToMimeBd(email, rendered);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  try {
    rendered.writeFile('signed.eml');
  } on ChilkatException {
    print('Failed: rendered.WriteFile.');
    return;
  }

  print('Saved signed.eml.');
}