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
(AutoIt) Extract PKCS7 Signature DigestDemonstrates how to extract a signature digest from a PKCS7 signature.
; This example requires the Chilkat Crypt API to have been previously unlocked. ; See Unlock Chilkat Crypt for sample code. $oCrypt = ObjCreate("Chilkat.Crypt2") Local $sP7mFile = "qa_data/p7m/test.pdf.p7m" Local $sOutPath = "qa_output/test.pdf" ; First let's see if this .p7m signature can be verified, and the original file extracted. Local $bVerified = $oCrypt.VerifyP7M($sP7mFile,$sOutPath) If ($bVerified <> True) Then ConsoleWrite($oCrypt.LastErrorText & @CRLF) Exit EndIf ; How many signers? ; (The NumSignerCerts property is set whenever a signature is verified.) ConsoleWrite("Num Signers: " & $oCrypt.NumSignerCerts & @CRLF) ; Load the .p7m into memory... $oPkcs7Data = ObjCreate("Chilkat.BinData") $oPkcs7Data.LoadFile($sP7mFile) ; 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. $oSbBase64 = ObjCreate("Chilkat.StringBuilder") Local $sHexStr = $oPkcs7Data.GetEncodedChunk(0,2,"hex") $oSbBase64.Append($sHexStr) Local $bHaveBase64 = False If ($oSbBase64.ContentsEqual("4D49",True) = True) Then $bHaveBase64 = True $oSbBase64.Clear $oSbBase64.AppendBd($oPkcs7Data,"utf-8",0,0) EndIf ; Get each signer's signature digest. $oCrypt.EncodingMode = "base64" Local $i = 0 Local $sDigest While $i < $oCrypt.NumSignerCerts If ($bHaveBase64) Then $sDigest = $oCrypt.Pkcs7ExtractDigest($i,$oSbBase64.GetAsString()) Else $sDigest = $oCrypt.Pkcs7ExtractDigest($i,$oPkcs7Data.GetEncoded("base64")) EndIf If ($oCrypt.LastMethodSuccess <> True) Then ConsoleWrite($oCrypt.LastErrorText & @CRLF) Exit EndIf ConsoleWrite("Signer " & ($i + 1) & " digest = " & $sDigest & @CRLF) $i = $i + 1 Wend |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.