Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loCrypt
LOCAL lcInFile
LOCAL lcOutFile
LOCAL loJson
LOCAL i
LOCAL lnCount_i
LOCAL lcStrVal
LOCAL lcCertSerialNumber
LOCAL lcCertIssuerCN
LOCAL lcCertIssuerDN
LOCAL lcCertDigestAlgOid
LOCAL lcCertDigestAlgName
LOCAL lcContentType
LOCAL lcSigningTime
LOCAL lcMessageDigest
LOCAL lcSigningAlgOid
LOCAL lcSignerDigest
LOCAL j
LOCAL lnCount_j
LOCAL lcOid
LOCAL lcOidName
LOCAL lcDer

lnSuccess = 0

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

loCrypt = CreateObject('Chilkat.Crypt2')

lcInFile = "qa_data/p7m/brainpoolP256r1.p7m"
lcOutFile = "qa_output/something.dat"

* Verify and extract the signed data.
lnSuccess = loCrypt.VerifyP7M(lcInFile,lcOutFile)
IF (lnSuccess = 0) THEN
    ? loCrypt.LastErrorText
    RELEASE loCrypt
    CANCEL
ENDIF

* Examine details about the signature(s)
loJson = CreateObject('Chilkat.JsonObject')
loCrypt.GetLastJsonData(loJson)
loJson.EmitCompact = 0
? loJson.Emit()

* 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 = 0
lnCount_i = loJson.SizeOfArray("pkcs7.verify.digestAlgorithms")
DO WHILE i < lnCount_i
    loJson.I = i
    lcStrVal = loJson.StringOf("pkcs7.verify.digestAlgorithms[i]")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJson.SizeOfArray("pkcs7.verify.signerInfo")
DO WHILE i < lnCount_i
    loJson.I = i
    lcCertSerialNumber = loJson.StringOf("pkcs7.verify.signerInfo[i].cert.serialNumber")
    lcCertIssuerCN = loJson.StringOf("pkcs7.verify.signerInfo[i].cert.issuerCN")
    lcCertIssuerDN = loJson.StringOf("pkcs7.verify.signerInfo[i].cert.issuerDN")
    lcCertDigestAlgOid = loJson.StringOf("pkcs7.verify.signerInfo[i].cert.digestAlgOid")
    lcCertDigestAlgName = loJson.StringOf("pkcs7.verify.signerInfo[i].cert.digestAlgName")
    lcContentType = loJson.StringOf("pkcs7.verify.signerInfo[i].contentType")
    lcSigningTime = loJson.StringOf("pkcs7.verify.signerInfo[i].signingTime")
    lcMessageDigest = loJson.StringOf("pkcs7.verify.signerInfo[i].messageDigest")
    lcSigningAlgOid = loJson.StringOf("pkcs7.verify.signerInfo[i].signingAlgOid")
    lcSignerDigest = loJson.StringOf("pkcs7.verify.signerInfo[i].signerDigest")
    j = 0
    lnCount_j = loJson.SizeOfArray("pkcs7.verify.signerInfo[i].authAttr")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcOid = loJson.StringOf("pkcs7.verify.signerInfo[i].authAttr[j].oid")
        lcOidName = loJson.StringOf("pkcs7.verify.signerInfo[i].authAttr[j].oidName")
        lcDer = loJson.StringOf("pkcs7.verify.signerInfo[i].authAttr[j].der")
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

? "Success!"

RELEASE loCrypt
RELEASE loJson