Sample code for 30+ languages & platforms
Xbase++ 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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oEmail
LOCAL oCert
LOCAL oMail
LOCAL oRendered

nSuccess := 0

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

oEmail := CreateObject("Chilkat.Email")
nSuccess := oEmail:LoadEml("message.eml")
IF (nSuccess != 1)
    ? oEmail:LastErrorText
    oEmail:destroy()
    RETURN
ENDIF

oCert := CreateObject("Chilkat.Cert")
nSuccess := oCert:LoadPfxFile("signer.pfx", "PFX_PASSWORD")
IF (nSuccess != 1)
    ? oCert:LastErrorText
    oEmail:destroy()
    oCert:destroy()
    RETURN
ENDIF

nSuccess := oEmail:SetSigningCert(oCert)
IF (nSuccess != 1)
    ? oEmail:LastErrorText
    oEmail:destroy()
    oCert:destroy()
    RETURN
ENDIF

oEmail:SigningAlg := "pss"
oEmail:SigningHashAlg := "sha256"
oEmail:SendSigned := 1
oMail := CreateObject("Chilkat.MailMan")
oMail:OpaqueSigning := 0
oRendered := CreateObject("Chilkat.BinData")
nSuccess := oMail:RenderToMimeBd(oEmail, oRendered)
IF (nSuccess != 1)
    ? oMail:LastErrorText
    oEmail:destroy()
    oCert:destroy()
    oMail:destroy()
    oRendered:destroy()
    RETURN
ENDIF

nSuccess := oRendered:WriteFile("signed.eml")
IF (nSuccess != 1)
    ? "Failed: rendered.WriteFile."
    oEmail:destroy()
    oCert:destroy()
    oMail:destroy()
    oRendered:destroy()
    RETURN
ENDIF

? "Saved signed.eml."

oEmail:destroy()
oCert:destroy()
oMail:destroy()
oRendered:destroy()