DataFlex
DataFlex
Example: Mime.GetDecryptCertInfo method
Demonstrates theGetDecryptCertInfo method.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMime
Variant vJson
Handle hoJson
String sSerial
String sIssuerCN
Integer i
Integer iCount
String sTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatMime)) To hoMime
If (Not(IsComObjectCreated(hoMime))) Begin
Send CreateComObject of hoMime
End
// 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"
Get ComLoadMimeFile Of hoMime "qa_data/mime/enveloped_data.eml" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
// 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.
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get pvComObject of hoJson to vJson
Get ComGetDecryptCertInfo Of hoMime vJson To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
Set ComEmitCompact Of hoJson To False
Get ComEmit Of hoJson To sTemp1
Showln sTemp1
// Sample output:
// {
// "recipientInfo": [
// {
// "serial": "****",
// "issuerCN": "****"
// }
// ]
// }
// Get each certificate's information like this:
Move 0 To i
Get ComSizeOfArray Of hoJson "recipientInfo" To iCount
While (i < iCount)
Set ComI Of hoJson To i
Get ComStringOf Of hoJson "recipientInfo[i].serial" To sSerial
Get ComStringOf Of hoJson "recipientInfo[i].issuerCN" To sIssuerCN
Move (i + 1) To i
Loop
End_Procedure