Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.5.0+

Sign PDF using ARSS (Aruba Remote Signing Service)

See more Signing in the Cloud Examples

Demonstrates how to digitally sign a PDF using the Aruba Remote Signing Service (ARSS). The example loads a local PDF and certificate, configures the ARSS cloud signer credentials, specifies the OTP authentication type with typeOtpAuth, and creates an LTV-enabled signed PDF where the private key remains protected on the Aruba signing server.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoPdf
    Variant vJson
    Handle hoJson
    Variant vCert
    Handle hoCert
    Variant vJsonArss
    Handle hoJsonArss
    String sTemp1

    Move False To iSuccess

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatPdf)) To hoPdf
    If (Not(IsComObjectCreated(hoPdf))) Begin
        Send CreateComObject of hoPdf
    End

    //  Load the PDF that will be digitally signed.
    Get ComLoadFile Of hoPdf "qa_data/pdf/hello.pdf" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPdf To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Signing options are specified in a JSON object.
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End

    //  Enable LTV (Long-Term Validation).
    //  When ltvOcsp is true, OCSP validation information is embedded in the PDF
    //  so that signature validation can continue to succeed in the future,
    //  even if the original OCSP responder is no longer available.
    Get ComUpdateBool Of hoJson "ltvOcsp" True To iSuccess

    //  Specify the visual appearance of the signature on the PDF page.
    Get ComUpdateInt Of hoJson "page" 1 To iSuccess
    Get ComUpdateString Of hoJson "appearance.y" "top" To iSuccess
    Get ComUpdateString Of hoJson "appearance.x" "left" To iSuccess
    Get ComUpdateString Of hoJson "appearance.fontScale" "10.0" To iSuccess

    //  Text lines displayed in the visible signature appearance.
    //  Special values such as "cert_cn" and "current_dt" are replaced
    //  with the certificate common name and current date/time.
    Get ComUpdateString Of hoJson "appearance.text[0]" "Digitally signed by: cert_cn" To iSuccess
    Get ComUpdateString Of hoJson "appearance.text[1]" "current_dt" To iSuccess
    Get ComUpdateString Of hoJson "appearance.text[2]" "This is an LTV-enabled signature." To iSuccess

    //  Load the signing certificate.
    //  
    //  The private key is NOT stored locally.  Instead, the private key is
    //  stored and protected on the Aruba Remote Signing Service (ARSS).
    //  
    //  Even though the signing operation will occur remotely, Chilkat still
    //  needs the corresponding public certificate locally so that it can
    //  construct the CMS/PAdES signature and embed the certificate chain
    //  in the signed PDF.
    Get Create (RefClass(cComChilkatCert)) To hoCert
    If (Not(IsComObjectCreated(hoCert))) Begin
        Send CreateComObject of hoCert
    End
    Get ComLoadFromFile Of hoCert "qa_data/certs/myCert.cer" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoCert To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Configure Aruba Remote Signing Service (ARSS) credentials.
    //  
    //  When SetCloudSigner is called, Chilkat is instructed to perform
    //  cryptographic signing operations through the ARSS web service.
    //  The PDF is assembled locally, but the actual RSA signature operation
    //  is performed remotely using the private key held by Aruba.
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonArss
    If (Not(IsComObjectCreated(hoJsonArss))) Begin
        Send CreateComObject of hoJsonArss
    End

    //  Required.  Indicates that the cloud signing provider is ARSS.
    Get ComUpdateString Of hoJsonArss "service" "ARSS" To iSuccess

    //  The ARSS certificate identifier (for example, "AS0").
    //  This identifies which remote certificate/private key pair should be used.
    //  The remote certificate should correspond to the certificate loaded above.
    Get ComUpdateString Of hoJsonArss "certID" "YOUR_ARSS_CERT_ID" To iSuccess

    //  OTP password associated with the Aruba remote-signing account.
    //  Depending on the ARSS configuration, an OTP may be required to
    //  authorize each signing operation.
    Get ComUpdateString Of hoJsonArss "otpPwd" "YOUR_OTP_PWD" To iSuccess

    //  Specifies the OTP authentication environment.
    //  
    //  Common values are:
    //    "demoprod" - Demo/Test environment
    //    "prod"     - Production environment
    //  
    //  This value is sent to the ARSS service and determines how the OTP
    //  authentication is validated.  The correct value depends on the type
    //  of Aruba account and environment that has been provisioned.
    //  
    //  If signing fails with an authentication-related error, verify that
    //  the typeOtpAuth value matches the environment associated with the
    //  ARSS account credentials being used.
    Get ComUpdateString Of hoJsonArss "typeOtpAuth" "demoprod" To iSuccess

    //  ARSS account username.
    Get ComUpdateString Of hoJsonArss "user" "YOUR_ARSS_USERNAME" To iSuccess

    //  ARSS account password.
    Get ComUpdateString Of hoJsonArss "userPWD" "YOUR_ARSS_PASSWORD" To iSuccess

    //  Beginning with Chilkat v11.5.0, the ARSS endpoint can be explicitly
    //  specified.  This allows the application to target a particular
    //  Aruba signing service endpoint when required.
    Get ComUpdateString Of hoJsonArss "endpoint" "https://app1.firma-remota.it/ArubaSignerService/webresources/signerservice" To iSuccess

    Get pvComObject of hoJsonArss to vJsonArss
    Get ComSetCloudSigner Of hoCert vJsonArss To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoCert To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Associate the certificate with the PDF object.
    //  All subsequent signing operations will use this certificate.
    Get pvComObject of hoCert to vCert
    Get ComSetSigningCert Of hoPdf vCert To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPdf To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Create the signed PDF.
    //  
    //  Chilkat performs all PDF processing locally.  When the time comes
    //  to generate the cryptographic signature value, Chilkat sends the
    //  hash to ARSS, which signs it using the remote private key and returns
    //  the signature.  The private key never leaves the Aruba service.
    Get pvComObject of hoJson to vJson
    Get ComSignPdf Of hoPdf vJson "qa_output/hello_ltv_signed.pdf" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPdf To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "The PDF has been successfully cryptographically signed with long-term validation."


End_Procedure