Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.4.0+

Example: Mime.GetDecryptCertInfo method

Demonstrates the GetDecryptCertInfo method.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oMime
LOCAL oJson
LOCAL cSerial
LOCAL cIssuerCN
LOCAL i
LOCAL nCount

nSuccess := 0

oMime := CreateObject("Chilkat.Mime")

//  Load MIME that is has Content-Type like this:
//  Content-Type: application/pkcs7-mime; smime-type="enveloped-data"; name="smime.p7m"; smime-type="enveloped-data"
nSuccess := oMime:LoadMimeFile("qa_data/mime/enveloped_data.eml")
IF (nSuccess == 0)
    ? oMime:LastErrorText
    oMime:destroy()
    RETURN
ENDIF

//  Get information about the certificate that would be needed to decrypt.
//  An enveloped-data can potentially be decrypted by multiple certificates if it was encrypted in a way that allows it,
//  but in most cases, only a single certificate with associated private key (that of the message recipient) is possible.
oJson := CreateObject("Chilkat.JsonObject")
nSuccess := oMime:GetDecryptCertInfo(oJson)
IF (nSuccess == 0)
    ? oMime:LastErrorText
    oMime:destroy()
    oJson:destroy()
    RETURN
ENDIF

oJson:EmitCompact := 0
? oJson:Emit()

//  Sample output:

//  {
//    "recipientInfo": [
//      {
//        "serial": "****",
//        "issuerCN": "****"
//      }
//    ]
//  }

//  Get each certificate's information like this:

i := 0
nCount := oJson:SizeOfArray("recipientInfo")
DO WHILE i < nCount
    oJson:I := i
    cSerial := oJson:StringOf("recipientInfo[i].serial")
    cIssuerCN := oJson:StringOf("recipientInfo[i].issuerCN")
    i := i + 1
ENDDO

oMime:destroy()
oJson:destroy()