Sample code for 30+ languages & platforms
DataFlex

Get the Signer Certificate of a Signed Email

See more Email Object Examples

Demonstrates the Chilkat Email.LastSignerCert method, which copies the certificate for the signer at a given zero-based index into a Cert object. Most signed emails have one signer (index 0), but a message can have more than one. This example loads a signed email and reads the first signer's common name.

Background: Confirming that a signature is valid (see SignaturesValid) tells you the content wasn't altered, but not who signed it. LastSignerCert gives you the signer's certificate as an object so you can examine its subject and issuer and evaluate trust — an essential step before relying on a signature to establish the sender's identity.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    Variant vCert
    Handle hoCert
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    //  Demonstrates the LastSignerCert method, which copies the certificate for the signer at
    //  the given zero-based index into a Cert object.  Most signed emails have one signer
    //  (index 0), but a message can have more than one.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    Get ComLoadEml Of hoEmail "qa_data/eml/signed.eml" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComReceivedSigned Of hoEmail To bTemp1
    If (bTemp1 = True) Begin
        //  Get the certificate of the first signer (index 0).
        Get Create (RefClass(cComChilkatCert)) To hoCert
        If (Not(IsComObjectCreated(hoCert))) Begin
            Send CreateComObject of hoCert
        End
        Get pvComObject of hoCert to vCert
        Get ComLastSignerCert Of hoEmail 0 vCert To iSuccess
        If (iSuccess = True) Begin
            Get ComSubjectCN Of hoCert To sTemp1
            Showln "Signer certificate (CN): " sTemp1
        End

    End

    //  Note: The path "qa_data/..." is a relative local filesystem path,
    //  relative to the current working directory of the running application.


End_Procedure