Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Use RSAES-OAEP Padding for Encrypted Email

See more Email Object Examples

Demonstrates the Chilkat Email.OaepPadding property, which selects the RSA encryption scheme used when encrypting email. The default is false, which selects RSAES PKCS1-v1_5; setting it to true selects RSAES-OAEP. This affects the RSA key-encryption step used for S/MIME encryption — it does not change the symmetric content-encryption algorithm chosen by Pkcs7CryptAlg. This example enables OAEP padding.

Background: Recall that S/MIME encrypts the message body with a one-time symmetric key, then encrypts that key with RSA. "Padding" is how the key bytes are formatted before RSA is applied. The older PKCS1-v1_5 padding has known theoretical weaknesses, while RSAES-OAEP adds randomness and a hash-based construction that is provably more secure and is the modern recommendation. Both endpoints must agree, so a recipient's software has to support OAEP to read the message.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Email;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  email: TEmail;

begin
  //  Demonstrates the Email.OaepPadding property, which selects the RSA encryption scheme
  //  used when encrypting email.  The default is false (RSAES PKCS1-v1_5).  Set it to true
  //  to use RSAES-OAEP.  This affects only the RSA key-encryption step, not the symmetric
  //  content-encryption algorithm selected by Pkcs7CryptAlg.

  email := TEmail.Create;
  email.Subject := 'Encrypted with RSAES-OAEP';
  email.Body := 'This message uses OAEP padding for the RSA key encryption.';

  //  Use RSAES-OAEP instead of the older PKCS1-v1_5 scheme.
  email.OaepPadding := True;

  WriteLn('OaepPadding = ' + email.OaepPadding);


  email.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.