Perl Requires Chilkat v11.0.0+
Perl
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 Perl Downloads
use strict;
use warnings;
use Chilkat2;
# Assumes Chilkat is unlocked. See Global Unlock Sample.
my $email = Chilkat2::Email->new;
my $success = $email->LoadEml('message.eml');
if (!$success) {
print $email->LastErrorText, "\n";
exit;
}
my $cert = Chilkat2::Cert->new;
$success = $cert->LoadPfxFile('signer.pfx', 'PFX_PASSWORD');
if (!$success) {
print $cert->LastErrorText, "\n";
exit;
}
$success = $email->SetSigningCert($cert);
if (!$success) {
print $email->LastErrorText, "\n";
exit;
}
$email->SigningAlg('pss');
$email->SigningHashAlg('sha256');
$email->SendSigned(1);
my $mail = Chilkat2::MailMan->new;
$mail->OpaqueSigning(0);
my $rendered = Chilkat2::BinData->new;
$success = $mail->RenderToMimeBd($email, $rendered);
if (!$success) {
print $mail->LastErrorText, "\n";
exit;
}
$success = $rendered->WriteFile('signed.eml');
if (!$success) {
print "Failed: rendered.WriteFile.\n";
exit;
}
print "Saved signed.eml.\n";