DataFlex
DataFlex
Get the Certificate Used for Decryption
See more MIME Examples
Loads a CMS/PKCS #7 encrypted S/MIME message and decrypts it back to the original MIME content.
After a successful decryption, LastDecryptCert loads the certificate(s) actually used into a Cert object, indexed from zero up to NumDecryptCerts minus one.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background. Following decryption or security unwrapping, Chilkat records which certificate(s) were used. LastDecryptCert retrieves them so the application can report or verify the identity involved.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMime
String sPfxPassword
Integer n
Variant vCert
Handle hoCert
Integer i
String sTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatMime)) To hoMime
If (Not(IsComObjectCreated(hoMime))) Begin
Send CreateComObject of hoMime
End
Get ComLoadMimeFile Of hoMime "qa_data/encrypted.eml" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
// Configure a decryption source and decrypt.
Move "myPfxPassword" To sPfxPassword
Get ComAddPfxSourceFile Of hoMime "qa_data/recipient.pfx" sPfxPassword To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComDecrypt Of hoMime To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
// After a successful decryption, load the certificate(s) that were used. The 1st argument is the
// zero-based index and the 2nd is a Cert that receives the certificate.
Get ComNumDecryptCerts Of hoMime To n
Get Create (RefClass(cComChilkatCert)) To hoCert
If (Not(IsComObjectCreated(hoCert))) Begin
Send CreateComObject of hoCert
End
For i From 0 To (n - 1)
Get pvComObject of hoCert to vCert
Get ComLastDecryptCert Of hoMime i vCert To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComSubjectCN Of hoCert To sTemp1
Showln "Decrypted with: " sTemp1
Loop
End_Procedure