Delphi DLL Requires Chilkat v11.0.0+
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
email: HCkEmail;
cert: HCkCert;
mail: HCkMailMan;
rendered: HCkBinData;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email := CkEmail_Create();
success := CkEmail_LoadEml(email,'message.eml');
if (success <> True) then
begin
Memo1.Lines.Add(CkEmail__lastErrorText(email));
Exit;
end;
cert := CkCert_Create();
success := CkCert_LoadPfxFile(cert,'signer.pfx','PFX_PASSWORD');
if (success <> True) then
begin
Memo1.Lines.Add(CkCert__lastErrorText(cert));
Exit;
end;
success := CkEmail_SetSigningCert(email,cert);
if (success <> True) then
begin
Memo1.Lines.Add(CkEmail__lastErrorText(email));
Exit;
end;
CkEmail_putSigningAlg(email,'pss');
CkEmail_putSigningHashAlg(email,'sha256');
CkEmail_putSendSigned(email,True);
mail := CkMailMan_Create();
CkMailMan_putOpaqueSigning(mail,False);
rendered := CkBinData_Create();
success := CkMailMan_RenderToMimeBd(mail,email,rendered);
if (success <> True) then
begin
Memo1.Lines.Add(CkMailMan__lastErrorText(mail));
Exit;
end;
success := CkBinData_WriteFile(rendered,'signed.eml');
if (success <> True) then
begin
Memo1.Lines.Add('Failed: rendered.WriteFile.');
Exit;
end;
Memo1.Lines.Add('Saved signed.eml.');
CkEmail_Dispose(email);
CkCert_Dispose(cert);
CkMailMan_Dispose(mail);
CkBinData_Dispose(rendered);