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) Verify a .p7m and get Algorithm InformationDemonstrates how to verify a .p7m and then examine the algorithms used by the signature.
IncludeFile "CkCrypt2.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. crypt.i = CkCrypt2::ckCreate() If crypt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf inFile.s = "qa_data/p7m/brainpoolP256r1.p7m" outFile.s = "qa_output/something.dat" ; Verify and extract the signed data. success.i = CkCrypt2::ckVerifyP7M(crypt,inFile,outFile) If success = 0 Debug CkCrypt2::ckLastErrorText(crypt) CkCrypt2::ckDispose(crypt) ProcedureReturn EndIf ; Examine details about the signature(s) json.i = CkCrypt2::ckLastJsonData(crypt) CkJsonObject::setCkEmitCompact(json, 0) Debug CkJsonObject::ckEmit(json) ; Sample output ; { ; "pkcs7": { ; "verify": { ; "digestAlgorithms": [ ; "sha256" ; ], ; "signerInfo": [ ; { ; "cert": { ; "serialNumber": "FFFFE552B302FFFFFF1E34C3ACEB2FFFF", ; "issuerCN": "The common name of the cert...", ; "issuerDN": "", ; "digestAlgOid": "2.16.840.1.101.3.4.2.1", ; "digestAlgName": "SHA256" ; }, ; "contentType": "1.2.840.113549.1.7.1", ; "signingTime": "190409140500Z", ; "messageDigest": "lQe9If7vZKFf/NlSYu5Esmlw3phVK/RFsbbb1uH73t8=", ; "signingAlgOid": "1.2.840.10045.4.3.2", ; "signerDigest": "lQe9If7vZKFf/NlSYu5Esmlw3phVK/RFsbbb1uH73t8=", ; "authAttr": [ ; { ; "oid": "1.2.840.113549.1.9.3", ; "oidName": "contentType" ; }, ; { ; "oid": "1.2.840.113549.1.9.5", ; "oidName": "signingTime" ; }, ; { ; "oid": "1.2.840.113549.1.9.52", ; "oidName": "1.2.840.113549.1.9.52", ; "der": "MBs ... AwI=" ; }, ; { ; "oid": "1.2.840.113549.1.9.4", ; "oidName": "messageDigest" ; }, ; { ; "oid": "1.2.840.113549.1.9.16.2.47", ; "oidName": "signingCertificateV2", ; "der": "MCYw .. 7PlQ==" ; }, ; { ; "oid": "1.2.840.113549.1.9.20", ; "oidName": "1.2.840.113549.1.9.20" ; } ; ] ; } ; ] ; } ; } ; } ; Code for parsing the above JSON... i.i count_i.i strVal.s certSerialNumber.s certIssuerCN.s certIssuerDN.s certDigestAlgOid.s certDigestAlgName.s contentType.s signingTime.s messageDigest.s signingAlgOid.s signerDigest.s j.i count_j.i oid.s oidName.s der.s i = 0 count_i = CkJsonObject::ckSizeOfArray(json,"pkcs7.verify.digestAlgorithms") While i < count_i CkJsonObject::setCkI(json, i) strVal = CkJsonObject::ckStringOf(json,"pkcs7.verify.digestAlgorithms[i]") i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(json,"pkcs7.verify.signerInfo") While i < count_i CkJsonObject::setCkI(json, i) certSerialNumber = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].cert.serialNumber") certIssuerCN = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].cert.issuerCN") certIssuerDN = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].cert.issuerDN") certDigestAlgOid = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].cert.digestAlgOid") certDigestAlgName = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].cert.digestAlgName") contentType = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].contentType") signingTime = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].signingTime") messageDigest = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].messageDigest") signingAlgOid = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].signingAlgOid") signerDigest = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].signerDigest") j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"pkcs7.verify.signerInfo[i].authAttr") While j < count_j CkJsonObject::setCkJ(json, j) oid = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].authAttr[j].oid") oidName = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].authAttr[j].oidName") der = CkJsonObject::ckStringOf(json,"pkcs7.verify.signerInfo[i].authAttr[j].der") j = j + 1 Wend i = i + 1 Wend CkJsonObject::ckDispose(json) Debug "Success!" CkCrypt2::ckDispose(crypt) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.