Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Extract PKCS7 Signature DigestDemonstrates how to extract a signature digest from a PKCS7 signature.
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.