Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(DataFlex) Create CAdES Signature (.p7s) Compliant with ICP-Brazil Digital Signature Standard

Demonstrates how to create a CMS signature w/ policy ID that is compliant with the ICP-Brazil Digital Signature Standard.

Note: This example requires Chilkat v9.5.0.79 or greater.

For more information, see https://verificador.iti.gov.br/verifier-2.3.10/

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoCrypt
    Variant vCert
    Handle hoCert
    Boolean iSuccess
    Handle hoAttrs
    String sInFile
    String sOutFile
    String sTemp1

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

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

    Get Create (RefClass(cComChilkatCert)) To hoCert
    If (Not(IsComObjectCreated(hoCert))) Begin
        Send CreateComObject of hoCert
    End
    Get ComLoadPfxFile Of hoCert "mySigningCert.pfx" "pfxPassword" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoCert To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get pvComObject of hoCert to vCert
    Get ComSetSigningCert Of hoCrypt vCert To iSuccess
    Set ComHashAlgorithm Of hoCrypt To "sha256"

    // Create JSON to indicate which signing attributes to include.
    Get Create (RefClass(cComChilkatJsonObject)) To hoAttrs
    If (Not(IsComObjectCreated(hoAttrs))) Begin
        Send CreateComObject of hoAttrs
    End
    Get ComUpdateBool Of hoAttrs "contentType" True To iSuccess
    Get ComUpdateBool Of hoAttrs "signingTime" True To iSuccess
    Get ComUpdateBool Of hoAttrs "messageDigest" True To iSuccess
    Get ComUpdateString Of hoAttrs "contentHint.text" 'Content-Type: application/octet-stream' + (character(13)) + (character(10)) + 'Content-Disposition: attachment;filename="documento.pdf"' To iSuccess
    Get ComUpdateString Of hoAttrs "contentHint.oid" "1.2.840.113549.1.7.1" To iSuccess
    Get ComUpdateString Of hoAttrs "policyId.id" "2.16.76.1.7.1.1.2.3" To iSuccess
    Get ComUpdateString Of hoAttrs "policyId.hash" "sW6Iu/dzIqZ5lbeQeHeO09DqfIhYe29tUYtxXo92o9U=" To iSuccess
    Get ComUpdateString Of hoAttrs "policyId.hashAlg" "SHA256" To iSuccess
    Get ComUpdateString Of hoAttrs "policyId.uri" "http://politicas.icpbrasil.gov.br/PA_AD_RB_v2_3.der" To iSuccess
    Get ComUpdateBool Of hoAttrs "signingCertificateV2" True To iSuccess

    Get ComEmit Of hoAttrs To sTemp1
    Set ComSigningAttributes Of hoCrypt To sTemp1

    // The input file can be any type of file.
    Move "toBeSigned.pdf" To sInFile
    Move "signed.pdf.p7s" To sOutFile

    Get ComCreateP7M Of hoCrypt sInFile sOutFile To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoCrypt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Success."


End_Procedure

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.