Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi ActiveX) Send Encrypted Email using RSAES-OAEP with AES-128 CBC and SHA256Demonstrates 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.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB; ... procedure TForm1.Button1Click(Sender: TObject); var cert: TChilkatCert; success: Integer; email: TChilkatEmail; mailman: TChilkatMailMan; begin // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Load an RSA-based certificate. // (Encrypting an email only requires the public key. Decrypting an email requires the private key.) cert := TChilkatCert.Create(Self); success := cert.LoadFromFile('qa_data/rsaes-oaep/cert.pem'); if (success <> 1) then begin Memo1.Lines.Add(cert.LastErrorText); Exit; end; email := TChilkatEmail.Create(Self); // Create a simple email. email.Subject := 'Sample RSAES-OAEP Encrypted Email'; email.Body := 'Sample RSAES-OAEP Encrypted Email'; email.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.) email.AddTo('Chilkat GMail','chilkat.support@gmail.com'); // Set the email object properties to indicate the desired encryption. email.Pkcs7CryptAlg := 'aes'; // If AES-256 is desired, set the following property to 256. email.Pkcs7KeyLength := 128; email.OaepPadding := 1; // Other choices for the OAEP hash algorithm are "sha1", "sha384", and "sha512" email.OaepHash := 'sha256'; // Provide the certificate to be used for encryption email.AddEncryptCert(cert.ControlInterface); // Don't forget to indicate that the email should be encrypted when sent.. email.SendEncrypted := 1; // The mailman object will do the RSAES-OAEP encryption when sending. mailman := TChilkatMailMan.Create(Self); // Set the SMTP settings for your email account on your mail server. mailman.SmtpUsername := 'SMTP_LOGIN'; mailman.SmtpPassword := 'SMTP_PASSWORD'; mailman.SmtpHost := 'MY_SMTP_DOMAIN_OR_IP'; mailman.SmtpPort := 587; mailman.StartTLS := 1; // Send the email. The mailman will encrypt the email as directed by the // property settings of the email object. success := mailman.SendEmail(email.ControlInterface); if (success <> 1) then begin Memo1.Lines.Add(mailman.LastErrorText); Exit; end; success := mailman.CloseSmtpConnection(); if (success <> 1) then begin Memo1.Lines.Add('Connection to SMTP server not closed cleanly.'); end; Memo1.Lines.Add('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= end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.