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
(Tcl) Verify a .p7m and get Algorithm InformationDemonstrates how to verify a .p7m and then examine the algorithms used by the signature.
load ./chilkat.dll # This example requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set crypt [new_CkCrypt2] set inFile "qa_data/p7m/brainpoolP256r1.p7m" set outFile "qa_output/something.dat" # Verify and extract the signed data. set success [CkCrypt2_VerifyP7M $crypt $inFile $outFile] if {$success == 0} then { puts [CkCrypt2_lastErrorText $crypt] delete_CkCrypt2 $crypt exit } # Examine details about the signature(s) # json is a CkJsonObject set json [CkCrypt2_LastJsonData $crypt] CkJsonObject_put_EmitCompact $json 0 puts [CkJsonObject_emit $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... set i 0 set count_i [CkJsonObject_SizeOfArray $json "pkcs7.verify.digestAlgorithms"] while {$i < $count_i} { CkJsonObject_put_I $json $i set strVal [CkJsonObject_stringOf $json "pkcs7.verify.digestAlgorithms[i]"] set i [expr $i + 1] } set i 0 set count_i [CkJsonObject_SizeOfArray $json "pkcs7.verify.signerInfo"] while {$i < $count_i} { CkJsonObject_put_I $json $i set certSerialNumber [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].cert.serialNumber"] set certIssuerCN [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].cert.issuerCN"] set certIssuerDN [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].cert.issuerDN"] set certDigestAlgOid [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].cert.digestAlgOid"] set certDigestAlgName [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].cert.digestAlgName"] set contentType [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].contentType"] set signingTime [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].signingTime"] set messageDigest [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].messageDigest"] set signingAlgOid [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].signingAlgOid"] set signerDigest [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].signerDigest"] set j 0 set count_j [CkJsonObject_SizeOfArray $json "pkcs7.verify.signerInfo[i].authAttr"] while {$j < $count_j} { CkJsonObject_put_J $json $j set oid [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].authAttr[j].oid"] set oidName [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].authAttr[j].oidName"] set der [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].authAttr[j].der"] set j [expr $j + 1] } set i [expr $i + 1] } delete_CkJsonObject $json puts "Success!" delete_CkCrypt2 $crypt |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.