Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicPythonRubySQL ServerSwiftTclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcel

Visual FoxPro Examples


ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)

Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Visual FoxPro) Send Encrypted Email using RSAES-OAEP with AES-128 CBC and SHA256

Demonstrates how to send encrypted email using RSAES-OAEP with SHA256 and AES-128 content encryption.

Note: This example requires Chilkat v9.5.0.67 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL loCert
LOCAL lnSuccess
LOCAL loEmail
LOCAL loMailman

*  This example requires the Chilkat Email API to have been previously unlocked.
*  See Unlock Chilkat MailMan for sample code.

*  Load an RSA-based certificate.
*  (Encrypting an email only requires the public key.  Decrypting an email requires the private key.)
loCert = CreateObject('Chilkat_9_5_0.Cert')
lnSuccess = loCert.LoadFromFile("qa_data/rsaes-oaep/cert.pem")
IF (lnSuccess <> 1) THEN
    ? loCert.LastErrorText
    RELEASE loCert
    CANCEL
ENDIF

loEmail = CreateObject('Chilkat_9_5_0.Email')

*  Create a simple email.
loEmail.Subject = "Sample RSAES-OAEP Encrypted Email"
loEmail.Body = "Sample RSAES-OAEP Encrypted Email"
loEmail.From = "support@chilkatsoft.com"

*  Add a recipient.
*  (The email is encrypted using the recipient's certificate.
*  If sending to multiple recipients, then the AddEncryptCert method would
*  need to be called once for each recipient's certificate.)
loEmail.AddTo("Chilkat GMail","chilkat.support@gmail.com")

*  Set the email object properties to indicate the desired encryption.
loEmail.Pkcs7CryptAlg = "aes"
*  If AES-256 is desired, set the following property to 256.
loEmail.Pkcs7KeyLength = 128
loEmail.OaepPadding = 1
*  Other choices for the OAEP hash algorithm are "sha1", "sha384", and "sha512"
loEmail.OaepHash = "sha256"

*  Provide the certificate to be used for encryption
loEmail.AddEncryptCert(loCert)

*  Don't forget to indicate that the email should be encrypted when sent..
loEmail.SendEncrypted = 1

*  The mailman object will do the RSAES-OAEP encryption when sending.
loMailman = CreateObject('Chilkat_9_5_0.MailMan')

*  Set the SMTP settings for your email account on your mail server.
loMailman.SmtpUsername = "SMTP_LOGIN"
loMailman.SmtpPassword = "SMTP_PASSWORD"
loMailman.SmtpHost = "MY_SMTP_DOMAIN_OR_IP"
loMailman.SmtpPort = 587
loMailman.StartTLS = 1

*  Send the email.  The mailman will encrypt the email as directed by the
*  property settings of the email object.
lnSuccess = loMailman.SendEmail(loEmail)
IF (lnSuccess <> 1) THEN
    ? loMailman.LastErrorText
    RELEASE loCert
    RELEASE loEmail
    RELEASE loMailman
    CANCEL
ENDIF

lnSuccess = loMailman.CloseSmtpConnection()
IF (lnSuccess <> 1) THEN
    ? "Connection to SMTP server not closed cleanly."
ENDIF

? "Mail Sent!"

*  -----------------------------------------------------------
*  This is an example of an RSAES-OAEP encrypted email
*  -----------------------------------------------------------

*  MIME-Version: 1.0
*  Date: Thu, 27 Apr 2017 08:43:32 -0500
*  Message-ID: <772DC039F0259C474BAC60240EA2BA2272402308@CHILKAT13>
*  Content-Type: application/pkcs7-mime; name="smime.p7m"; smime-type="enveloped-data"
*  Content-Transfer-Encoding: base64
*  X-Priority: 3 (Normal)
*  Subject: Sample RSAES-OAEP Encrypted Email
*  From: support@chilkatsoft.com
*  To: "Chilkat GMail" <chilkat.support@gmail.com>
*  Content-Disposition: attachment; filename="smime.p7m"
* 
*  MIICWQYJKoZIhvcNAQcDoIICSjCCAkYCAQAxggGgMIIBnAIBADB1MGgxCzAJBgNVBAYTAlVTMQsw
*  CQYDVQQIDAJJTDEQMA4GA1UEBwwHV2hlYXRvbjEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ
*  dHkgTHRkMRcwFQYDVQQDDA5DaGlsa2F0V2lkZ2V0cwIJAMRwugDmvniwMBwGCSqGSIb3DQEBBzAP
*  oA0wCwYJYIZIAWUDBAIBBIIBABr0E1dKJjK0FAYRz/NCtJmBeB0nUxgcuBnhGPI/UeyGub3cCo+K
*  G5F4/iVTBJqVvYIF5+fvBnyTginwv7OiUiFWLyihiFC3NIyZJO22+XMHpNatCffTPZk10WswkTgk
*  G3ApnRvGQAaldnFD0Hs8drPU4vBvY9QsjT7YDGa6u2NMX+sr1ewEZArqU0mNfJ6RsEYd5FQbFEVF
*  qLmnz8Dt+yhoJlUtfUd8TXIeqHRJ7RxKOTSzlBZaAdTv2QX4oL9IcAgZeTg5iw+yRPkSAwWyg+I/
*  7fybLsUpRGDHTGUU+AvHvP0kYKa1mkvccBVEC/+4hEyhpS1tWIR5ByY6vM76Z+8wgZwGCSqGSIb3
*  DQEHATAdBglghkgBZQMEAQIEEKqD0YDHX1NsVDaV32UczpeAcLteQyRPTV4hATjwcPiVelPfeWNs
*  xZKRGaEBqLM8+Y+V4ciCFoOlgJuOcP4m1PTHyilfzd+SCsKz5l1C7+sfPf36n2aacX6IWga59Bz5
*  QbWrOHDUT7O5PnGwKVgQFw3Cj4GrdPGWKcoqxB0HuKnj3WA=

RELEASE loCert
RELEASE loEmail
RELEASE loMailman


 

© 2000-2016 Chilkat Software, Inc. All Rights Reserved.