Sample code for 30+ languages & platforms
AutoIt

Verify a .p7m and get Algorithm Information

See more Digital Signatures Examples

Demonstrates how to verify a .p7m and then examine the algorithms used by the signature.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oCrypt = ObjCreate("Chilkat.Crypt2")

Local $sInFile = "qa_data/p7m/brainpoolP256r1.p7m"
Local $sOutFile = "qa_output/something.dat"

; Verify and extract the signed data.
$bSuccess = $oCrypt.VerifyP7M($sInFile,$sOutFile)
If ($bSuccess = False) Then
    ConsoleWrite($oCrypt.LastErrorText & @CRLF)
    Exit
EndIf

; Examine details about the signature(s)
$oJson = ObjCreate("Chilkat.JsonObject")
$oCrypt.GetLastJsonData $oJson
$oJson.EmitCompact = False
ConsoleWrite($oJson.Emit() & @CRLF)

; 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...
Local $i
Local $iCount_i
Local $strVal
Local $sCertSerialNumber
Local $sCertIssuerCN
Local $sCertIssuerDN
Local $sCertDigestAlgOid
Local $sCertDigestAlgName
Local $sContentType
Local $signingTime
Local $sMessageDigest
Local $signingAlgOid
Local $signerDigest
Local $iJ
Local $iCount_j
Local $sOid
Local $sOidName
Local $sDer

$i = 0
$iCount_i = $oJson.SizeOfArray("pkcs7.verify.digestAlgorithms")
While $i < $iCount_i
    $oJson.I = $i
    $strVal = $oJson.StringOf("pkcs7.verify.digestAlgorithms[i]")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJson.SizeOfArray("pkcs7.verify.signerInfo")
While $i < $iCount_i
    $oJson.I = $i
    $sCertSerialNumber = $oJson.StringOf("pkcs7.verify.signerInfo[i].cert.serialNumber")
    $sCertIssuerCN = $oJson.StringOf("pkcs7.verify.signerInfo[i].cert.issuerCN")
    $sCertIssuerDN = $oJson.StringOf("pkcs7.verify.signerInfo[i].cert.issuerDN")
    $sCertDigestAlgOid = $oJson.StringOf("pkcs7.verify.signerInfo[i].cert.digestAlgOid")
    $sCertDigestAlgName = $oJson.StringOf("pkcs7.verify.signerInfo[i].cert.digestAlgName")
    $sContentType = $oJson.StringOf("pkcs7.verify.signerInfo[i].contentType")
    $signingTime = $oJson.StringOf("pkcs7.verify.signerInfo[i].signingTime")
    $sMessageDigest = $oJson.StringOf("pkcs7.verify.signerInfo[i].messageDigest")
    $signingAlgOid = $oJson.StringOf("pkcs7.verify.signerInfo[i].signingAlgOid")
    $signerDigest = $oJson.StringOf("pkcs7.verify.signerInfo[i].signerDigest")
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("pkcs7.verify.signerInfo[i].authAttr")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $sOid = $oJson.StringOf("pkcs7.verify.signerInfo[i].authAttr[j].oid")
        $sOidName = $oJson.StringOf("pkcs7.verify.signerInfo[i].authAttr[j].oidName")
        $sDer = $oJson.StringOf("pkcs7.verify.signerInfo[i].authAttr[j].der")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend

ConsoleWrite("Success!" & @CRLF)