Visual FoxPro
Visual FoxPro
Set the Signing Certificate and Private Key
See more Email Object Examples
Demonstrates the Chilkat Email.SetSigningCert2 method, which explicitly sets the certificate and its corresponding private key as separate objects for sending digitally signed email. This example loads a .cer certificate and a PEM private key, sets both, and enables signed sending.
Background: When your signing certificate and its private key are stored separately — a public
.cer plus a PEM key file — rather than combined in a PFX, SetSigningCert2 accepts the two objects individually. It is the two-object counterpart to SetSigningCert, which takes a single certificate that already carries its private key.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loEmail
LOCAL loCert
LOCAL loPrivKey
lnSuccess = 0
* Demonstrates the SetSigningCert2 method, which explicitly sets the certificate and its
* corresponding private key (as separate objects) for sending digitally signed email.
loEmail = CreateObject('Chilkat.Email')
loEmail.Subject = "Signed email"
loEmail.Body = "This message will be sent with a digital signature."
loEmail.From = "alice@example.com"
loEmail.AddTo("Bob","bob@example.com")
* Load the certificate (public) and the matching private key from separate files.
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loCert.LoadFromFile("qa_data/certs/signer.cer")
IF (lnSuccess = 0) THEN
? loCert.LastErrorText
RELEASE loEmail
RELEASE loCert
CANCEL
ENDIF
loPrivKey = CreateObject('Chilkat.PrivateKey')
lnSuccess = loPrivKey.LoadPemFile("qa_data/certs/signer_privkey.pem")
IF (lnSuccess = 0) THEN
? loPrivKey.LastErrorText
RELEASE loEmail
RELEASE loCert
RELEASE loPrivKey
CANCEL
ENDIF
* Set the certificate and private key used to create the signature.
lnSuccess = loEmail.SetSigningCert2(loCert,loPrivKey)
IF (lnSuccess = 0) THEN
? loEmail.LastErrorText
RELEASE loEmail
RELEASE loCert
RELEASE loPrivKey
CANCEL
ENDIF
loEmail.SendSigned = 1
? "Signing certificate and private key set."
* Note: Paths such as "qa_data/..." are relative local filesystem paths,
* relative to the current working directory of the running application.
RELEASE loEmail
RELEASE loCert
RELEASE loPrivKey