Sample code for 30+ languages & platforms
DataFlex

Verify the Timestamp Server Token (if any) while Validating a CMS Signature

Demonstrates how to also validate the timestamp server token (if any) while validating a CMS signature.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoCrypt
    Handle hoCmsOptions
    String sOutputFile
    String sInFile
    String sTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt
    If (Not(IsComObjectCreated(hoCrypt))) Begin
        Send CreateComObject of hoCrypt
    End

    // Tell Chilkat to also validate the timestamp token if a timestamp exists in the CMS message's unauthenticated attributes.
    Get Create (RefClass(cComChilkatJsonObject)) To hoCmsOptions
    If (Not(IsComObjectCreated(hoCmsOptions))) Begin
        Send CreateComObject of hoCmsOptions
    End
    Get ComUpdateBool Of hoCmsOptions "ValidateTimestampTokens" True To iSuccess
    Get ComEmit Of hoCmsOptions To sTemp1
    Set ComCmsOptions Of hoCrypt To sTemp1

    Move "qa_output/original.xml" To sOutputFile
    Move "qa_data/p7m/fattura_signature.xml.p7m" To sInFile

    // Verify the signature and extract the contained file, which in this case is XML.
    Get ComVerifyP7M Of hoCrypt sInFile sOutputFile To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoCrypt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Signature validated."


End_Procedure