PureBasic
PureBasic
Add a PFX Source from BinData
See more Email Object Examples
Demonstrates the Chilkat Email.AddPfxSourceBd method, which adds PFX data held in a BinData object to the list of certificate and private-key sources used during decryption or signing. The second argument is the PFX password. Call it before obtaining the encrypted email so Chilkat can decrypt it automatically. This example loads a PFX into a BinData, adds it, and then loads an encrypted email.
Background: This is the in-memory (
BinData) counterpart to AddPfxSourceFile. It is the right choice when the PFX bytes come from somewhere other than a file — a database, a secrets manager, or an HTTP download — letting you supply the certificate and private key without first writing them to disk (which is preferable for sensitive key material).Chilkat PureBasic Downloads
IncludeFile "CkBinData.pb"
IncludeFile "CkEmail.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the AddPfxSourceBd method, which adds PFX data (held in a BinData) to the
; list of certificate and private-key sources used during decryption or signing. The
; second argument is the PFX password. Call it before obtaining the encrypted email.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Load PFX data into a BinData object.
bdPfx.i = CkBinData::ckCreate()
If bdPfx.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkBinData::ckLoadFile(bdPfx,"qa_data/certs/decryption.pfx")
If success = 0
Debug CkBinData::ckLastErrorText(bdPfx)
CkEmail::ckDispose(email)
CkBinData::ckDispose(bdPfx)
ProcedureReturn
EndIf
; Add the PFX as a source of the certificate + private key.
success = CkEmail::ckAddPfxSourceBd(email,bdPfx,"pfx_password")
If success = 0
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
CkBinData::ckDispose(bdPfx)
ProcedureReturn
EndIf
; Load an encrypted email; Chilkat decrypts it using the PFX source.
success = CkEmail::ckLoadEml(email,"qa_data/eml/encrypted.eml")
If success = 0
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
CkBinData::ckDispose(bdPfx)
ProcedureReturn
EndIf
Debug "Decrypted = " + Str(CkEmail::ckDecrypted(email))
; Note: Paths such as "qa_data/..." are relative local filesystem paths,
; relative to the current working directory of the running application.
CkEmail::ckDispose(email)
CkBinData::ckDispose(bdPfx)
ProcedureReturn
EndProcedure