Visual Basic 6.0 Requires Chilkat v11.0.0+
Visual Basic 6.0
Sign and encrypt an email with S/MIME
See more Email Object Examples
Use the sender’s signing PFX and the recipient’s public RSA certificate with with-attachments.eml, which has one recipient. Supply your own signing-key password from a credential store. Render to bytes to apply both S/MIME operations without connecting to SMTP.
Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim email As New ChilkatEmail
success = email.LoadEml("with-attachments.eml")
If (success <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
Dim signer As New ChilkatCert
success = signer.LoadPfxFile("signer.pfx","SIGNER_PASSWORD")
If (success <> 1) Then
Debug.Print signer.LastErrorText
Exit Sub
End If
Dim recipient As New ChilkatCert
success = recipient.LoadFromFile("recipient.cer")
If (success <> 1) Then
Debug.Print recipient.LastErrorText
Exit Sub
End If
success = email.SetSigningCert(signer)
If (success <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
success = email.SetEncryptCert(recipient)
If (success <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
email.SigningHashAlg = "sha256"
email.Pkcs7CryptAlg = "aes"
email.Pkcs7KeyLength = 256
email.OaepPadding = 1
email.OaepHash = "sha256"
email.OaepMgfHash = "sha256"
email.SendSigned = 1
email.SendEncrypted = 1
Dim mail As New ChilkatMailMan
Dim rendered As New ChilkatBinData
success = mail.RenderToMimeBd(email,rendered)
If (success <> 1) Then
Debug.Print mail.LastErrorText
Exit Sub
End If
success = rendered.WriteFile("signed-encrypted.eml")
If (success <> 1) Then
Debug.Print "Failed: rendered.WriteFile."
Exit Sub
End If
Debug.Print "Saved signed-encrypted.eml."