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

Swift

func chilkatTest() {
    var success: Bool = false

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

    let email = CkoEmail()!
    success = email.loadEml(mimePath: "message.eml")
    if success != true {
        print("\(email.lastErrorText!)")
        return
    }

    let cert = CkoCert()!
    success = cert.loadPfxFile(path: "signer.pfx", password: "PFX_PASSWORD")
    if success != true {
        print("\(cert.lastErrorText!)")
        return
    }

    success = email.setSigningCert(cert: cert)
    if success != true {
        print("\(email.lastErrorText!)")
        return
    }

    email.signingAlg = "pss"
    email.signingHashAlg = "sha256"
    email.sendSigned = true
    let mail = CkoMailMan()!
    mail.opaqueSigning = false
    let rendered = CkoBinData()!
    success = mail.render(toMimeBd: email, renderedMime: rendered)
    if success != true {
        print("\(mail.lastErrorText!)")
        return
    }

    success = rendered.writeFile(path: "signed.eml")
    if success != true {
        print("Failed: rendered.WriteFile.")
        return
    }

    print("Saved signed.eml.")

}