PureBasic
PureBasic
Add S/MIME Signature using PFX
See more MIME Examples
Add a digital signature to a MIME message using the certificate + private key from a PFX file.Chilkat PureBasic Downloads
IncludeFile "CkCert.pb"
IncludeFile "CkMime.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
mime.i = CkMime::ckCreate()
If mime.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Load a PFX file into a certificate object.
cert.i = CkCert::ckCreate()
If cert.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
pfxFilepath.s = "pfxFiles/something.pfx"
pfxPassword.s = "secret"
success = CkCert::ckLoadPfxFile(cert,pfxFilepath,pfxPassword)
If success = 0
Debug CkCert::ckLastErrorText(cert)
CkMime::ckDispose(mime)
CkCert::ckDispose(cert)
ProcedureReturn
EndIf
success = CkMime::ckSetBodyFromPlainText(mime,"This is the plain-text MIME body.")
CkMime::setCkCharset(mime, "utf-8")
CkMime::setCkEncoding(mime, "quoted-printable")
; Sign the MIME (adds a PKCS7 detached signature)
success = CkMime::ckAddDetachedSignature(mime,cert)
If success = 0
Debug CkMime::ckLastErrorText(mime)
CkMime::ckDispose(mime)
CkCert::ckDispose(cert)
ProcedureReturn
EndIf
; Save the S/MIME to a file.
success = CkMime::ckSaveMime(mime,"/temp/signedMime.txt")
If success = 0
Debug CkMime::ckLastErrorText(mime)
CkMime::ckDispose(mime)
CkCert::ckDispose(cert)
ProcedureReturn
EndIf
Debug "success!"
CkMime::ckDispose(mime)
CkCert::ckDispose(cert)
ProcedureReturn
EndProcedure