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
(DataFlex) P7S - Access Signature Information (date/time, certificate used, etc.)Examine a PKCS7 signature (.p7s) and get information about it. Note: This example requires Chilkat v9.5.0.75 or greater.
Use ChilkatAx-win32.pkg Procedure Test Variant vBd Handle hoBd Boolean iSuccess Handle hoCrypt Variant vJson Handle hoJson Integer i Integer iCount_i String sStrVal String sCertSerialNumber String sCertIssuerCN String sCertIssuerDN String sCertDigestAlgOid String sCertDigestAlgName String sContentType String sSigningTime String sMessageDigest String sSigningAlgOid String sSignerDigest Handle hoDt String sTemp1 // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // First load the .p7s file into a BinData object.. Get Create (RefClass(cComChilkatBinData)) To hoBd If (Not(IsComObjectCreated(hoBd))) Begin Send CreateComObject of hoBd End Get ComLoadFile Of hoBd "qa_data/p7s/sample.p7s" To iSuccess If (iSuccess <> True) Begin Showln "Failed to load .p7s file." Procedure_Return End // IMPORTANT: This example requires Chilkat v9.5.0.75 or greater. Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt If (Not(IsComObjectCreated(hoCrypt))) Begin Send CreateComObject of hoCrypt End // Assuming this is a signature that contains the original data that was signed.. Get pvComObject of hoBd to vBd Get ComOpaqueVerifyBd Of hoCrypt vBd To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoCrypt To sTemp1 Showln sTemp1 Procedure_Return End // Examine the LastJsonData after signature verification.. Get ComLastJsonData Of hoCrypt To vJson If (IsComObject(vJson)) Begin Get Create (RefClass(cComChilkatJsonObject)) To hoJson Set pvComObject Of hoJson To vJson End Set ComEmitCompact Of hoJson To False Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // -- // IMPORTANT: This example requires Chilkat v9.5.0.75 or greater. // -- // Sample output... // Go to http://tools.chilkat.io/jsonParse.cshtml // and paste the JSON into the online form to generate JSON parsing code. // { // "pkcs7": { // "verify": { // "digestAlgorithms": [ // "sha256" // ], // "signerInfo": [ // { // "cert": { // "serialNumber": "AAC5FC48C0FD8FBB", // "issuerCN": "AC ABCDEF RFB v5", // "issuerDN": "", // "digestAlgOid": "2.16.840.1.101.3.4.2.1", // "digestAlgName": "SHA-256" // }, // "contentType": "1.2.840.113549.1.7.1", // "signingTime": "180607195054Z", // "messageDigest": "trzyxXbZ96z2M4mncyZ7BNMV4yIT92+5sS27Fu64iG8=", // "signingAlgOid": "1.2.840.113549.1.1.11", // "signerDigest": "trzyxXbZ96z2M4mncyZ7BNMV4yIT92+5sS27Fu64iG8=" // }, // { // "cert": { // "serialNumber": "324FB38ABD59723F", // "issuerCN": "AC ABCDEF RFB v5", // "issuerDN": "", // "digestAlgOid": "2.16.840.1.101.3.4.2.1", // "digestAlgName": "SHA-256" // }, // "contentType": "1.2.840.113549.1.7.1", // "signingTime": "180608182517Z", // "messageDigest": "trzyxXbZ96z2M4mncyZ7BNMV4yIT92+5sS27Fu64iG8=", // "signingAlgOid": "1.2.840.113549.1.1.11", // "signerDigest": "trzyxXbZ96z2M4mncyZ7BNMV4yIT92+5sS27Fu64iG8=" // } // ] // } // } // } // Get Create (RefClass(cComCkDateTime)) To hoDt If (Not(IsComObjectCreated(hoDt))) Begin Send CreateComObject of hoDt End Move 0 To i Get ComSizeOfArray Of hoJson "pkcs7.verify.digestAlgorithms" To iCount_i While (i < iCount_i) Set ComI Of hoJson To i Get ComStringOf Of hoJson "pkcs7.verify.digestAlgorithms[i]" To sStrVal Move (i + 1) To i Loop Move 0 To i Get ComSizeOfArray Of hoJson "pkcs7.verify.signerInfo" To iCount_i While (i < iCount_i) Set ComI Of hoJson To i Get ComStringOf Of hoJson "pkcs7.verify.signerInfo[i].cert.serialNumber" To sCertSerialNumber Get ComStringOf Of hoJson "pkcs7.verify.signerInfo[i].cert.issuerCN" To sCertIssuerCN Get ComStringOf Of hoJson "pkcs7.verify.signerInfo[i].cert.issuerDN" To sCertIssuerDN Get ComStringOf Of hoJson "pkcs7.verify.signerInfo[i].cert.digestAlgOid" To sCertDigestAlgOid Get ComStringOf Of hoJson "pkcs7.verify.signerInfo[i].cert.digestAlgName" To sCertDigestAlgName Get ComStringOf Of hoJson "pkcs7.verify.signerInfo[i].contentType" To sContentType Get ComStringOf Of hoJson "pkcs7.verify.signerInfo[i].signingTime" To sSigningTime // The signingTime isin UTCTime format. // UTCTime values take the form of either "YYMMDDhhmm[ss]Z" or "YYMMDDhhmm[ss](+|-)hhmm" // Starting in Chilkat v9.5.0.77, the SetFromTimestamp method auto-recognizes the UTCTime format and parses it correctly. Get ComSetFromTimestamp Of hoDt sSigningTime To iSuccess // To get the signingTime in other date/time formats, look at the online reference documentation for CkDateTime. // There are numerous methods such as GetAsDateTime, GetAsIso8601, GetAsUnixTime, GetAsRfc822, etc. Get ComStringOf Of hoJson "pkcs7.verify.signerInfo[i].messageDigest" To sMessageDigest Get ComStringOf Of hoJson "pkcs7.verify.signerInfo[i].signingAlgOid" To sSigningAlgOid Get ComStringOf Of hoJson "pkcs7.verify.signerInfo[i].signerDigest" To sSignerDigest Move (i + 1) To i Loop Send Destroy of hoJson // println crypt.LastErrorText; Showln "Success." End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.