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
(PureBasic) Extract PKCS7 Signature DigestDemonstrates how to extract a signature digest from a PKCS7 signature.
IncludeFile "CkBinData.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkCrypt2.pb" Procedure ChilkatExample() ; This example requires the Chilkat Crypt API to have been previously unlocked. ; See Unlock Chilkat Crypt for sample code. crypt.i = CkCrypt2::ckCreate() If crypt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf p7mFile.s = "qa_data/p7m/test.pdf.p7m" outPath.s = "qa_output/test.pdf" ; First let's see if this .p7m signature can be verified, and the original file extracted. verified.i = CkCrypt2::ckVerifyP7M(crypt,p7mFile,outPath) If verified <> 1 Debug CkCrypt2::ckLastErrorText(crypt) CkCrypt2::ckDispose(crypt) ProcedureReturn EndIf ; How many signers? ; (The NumSignerCerts property is set whenever a signature is verified.) Debug "Num Signers: " + Str(CkCrypt2::ckNumSignerCerts(crypt)) ; Load the .p7m into memory... pkcs7Data.i = CkBinData::ckCreate() If pkcs7Data.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkBinData::ckLoadFile(pkcs7Data,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. sbBase64.i = CkStringBuilder::ckCreate() If sbBase64.i = 0 Debug "Failed to create object." ProcedureReturn EndIf hexStr.s = CkBinData::ckGetEncodedChunk(pkcs7Data,0,2,"hex") CkStringBuilder::ckAppend(sbBase64,hexStr) bHaveBase64.i = 0 If CkStringBuilder::ckContentsEqual(sbBase64,"4D49",1) = 1 bHaveBase64 = 1 CkStringBuilder::ckClear(sbBase64) CkStringBuilder::ckAppendBd(sbBase64,pkcs7Data,"utf-8",0,0) EndIf ; Get each signer's signature digest. CkCrypt2::setCkEncodingMode(crypt, "base64") i.i = 0 digest.s While i < CkCrypt2::ckNumSignerCerts(crypt) If bHaveBase64 digest = CkCrypt2::ckPkcs7ExtractDigest(crypt,i,CkStringBuilder::ckGetAsString(sbBase64)) Else digest = CkCrypt2::ckPkcs7ExtractDigest(crypt,i,CkBinData::ckGetEncoded(pkcs7Data,"base64")) EndIf If CkCrypt2::ckLastMethodSuccess(crypt) <> 1 Debug CkCrypt2::ckLastErrorText(crypt) CkCrypt2::ckDispose(crypt) CkBinData::ckDispose(pkcs7Data) CkStringBuilder::ckDispose(sbBase64) ProcedureReturn EndIf Debug "Signer " + Str(i + 1) + " digest = " + digest i = i + 1 Wend CkCrypt2::ckDispose(crypt) CkBinData::ckDispose(pkcs7Data) CkStringBuilder::ckDispose(sbBase64) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.