Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
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
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) Extract PKCS7 Signature Digest

Demonstrates how to extract a signature digest from a PKCS7 signature.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Crypt
string ls_P7mFile
string ls_OutPath
integer li_Verified
oleobject loo_Pkcs7Data
oleobject loo_SbBase64
string ls_HexStr
integer li_BHaveBase64
integer i
string ls_Digest

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

loo_Crypt = create oleobject
// Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")
if li_rc < 0 then
    destroy loo_Crypt
    MessageBox("Error","Connecting to COM object failed")
    return
end if

ls_P7mFile = "qa_data/p7m/test.pdf.p7m"
ls_OutPath = "qa_output/test.pdf"

// First let's see if this .p7m signature can be verified, and the original file extracted.
li_Verified = loo_Crypt.VerifyP7M(ls_P7mFile,ls_OutPath)
if li_Verified <> 1 then
    Write-Debug loo_Crypt.LastErrorText
    destroy loo_Crypt
    return
end if

// How many signers?
// (The NumSignerCerts property is set whenever a signature is verified.)
Write-Debug "Num Signers: " + string(loo_Crypt.NumSignerCerts)

// Load the .p7m into memory...
loo_Pkcs7Data = create oleobject
// Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0
li_rc = loo_Pkcs7Data.ConnectToNewObject("Chilkat.BinData")

loo_Pkcs7Data.LoadFile(ls_P7mFile)

// Check to see if this .p7m contains the binary bytes, or if it's
// already base64 encoded.  Get the 1st two bytes.  If the first two 
// bytes are the us-ascii values "MI", then we have base64.
loo_SbBase64 = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbBase64.ConnectToNewObject("Chilkat.StringBuilder")

ls_HexStr = loo_Pkcs7Data.GetEncodedChunk(0,2,"hex")
loo_SbBase64.Append(ls_HexStr)

li_BHaveBase64 = 0
if loo_SbBase64.ContentsEqual("4D49",1) = 1 then
    li_BHaveBase64 = 1
    loo_SbBase64.Clear()
    loo_SbBase64.AppendBd(loo_Pkcs7Data,"utf-8",0,0)
end if

// Get each signer's signature digest.
loo_Crypt.EncodingMode = "base64"
i = 0

do while i < loo_Crypt.NumSignerCerts
    if li_BHaveBase64 then
        ls_Digest = loo_Crypt.Pkcs7ExtractDigest(i,loo_SbBase64.GetAsString())
    else
        ls_Digest = loo_Crypt.Pkcs7ExtractDigest(i,loo_Pkcs7Data.GetEncoded("base64"))
    end if

    if loo_Crypt.LastMethodSuccess <> 1 then
        Write-Debug loo_Crypt.LastErrorText
        destroy loo_Crypt
        destroy loo_Pkcs7Data
        destroy loo_SbBase64
        return
    end if

    Write-Debug "Signer " + string(i + 1) + " digest = " + ls_Digest
    i = i + 1
loop


destroy loo_Crypt
destroy loo_Pkcs7Data
destroy loo_SbBase64

 

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