VBScript
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' Demonstrates the SetSigningCert2 method, which explicitly sets the certificate and its
' corresponding private key (as separate objects) for sending digitally signed email.
set email = CreateObject("Chilkat.Email")
email.Subject = "Signed email"
email.Body = "This message will be sent with a digital signature."
email.From = "alice@example.com"
success = email.AddTo("Bob","bob@example.com")
' Load the certificate (public) and the matching private key from separate files.
set cert = CreateObject("Chilkat.Cert")
success = cert.LoadFromFile("qa_data/certs/signer.cer")
If (success = 0) Then
outFile.WriteLine(cert.LastErrorText)
WScript.Quit
End If
set privKey = CreateObject("Chilkat.PrivateKey")
success = privKey.LoadPemFile("qa_data/certs/signer_privkey.pem")
If (success = 0) Then
outFile.WriteLine(privKey.LastErrorText)
WScript.Quit
End If
' Set the certificate and private key used to create the signature.
success = email.SetSigningCert2(cert,privKey)
If (success = 0) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
email.SendSigned = 1
outFile.WriteLine("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.
outFile.Close