Message Envelopes sample (Delphi)
Overview
This example illustrates the usage of message envelopes, in particular message envelopes with AES encryption.
When using message envelopes, the result stream contains only the envelope marker and an output stream processed by the envelope. For the AES Encryption Envelope, the data stream is encrypted. The correspondent side must use the same envelope with the same parameters (if encryption is used, the same password) to unwrap the message. Several envelopes can be applied to the message. In case of envelope or parameters mismatch, an exception will be raised.
![](../../../Samples/Delphi/MessageEnvelopes/server.png)
![](../../../Samples/Delphi/MessageEnvelopes/client.png)
Getting started
- Build and run the client and server projects.
- Test the example with different combinations of predefined envelopes, see what happens when envelopes don't match.
- Configure the envelopes to be used in the server and client applications: you can add, edit, delete and reorder envelopes using the corresponding buttons on the form.
Examine code
Envelopes can be configured at design time. The code shows how to configure them at run time. See how message envelopes are created at runtime and added to the message's envelopes collection:
procedure TMessageEnvelopes_ClientMainForm.FormCreate(Sender: TObject);
begin
CreateAESEnvelope('Marker A','Password A',True);
CheckListBox1.ItemIndex := 0;
CreateAESEnvelope('Marker B','Password B',False);
CreateAESEnvelope('Marker C','Password C',False);
end;
procedure TMessageEnvelopes_ClientMainForm.CreateAESEnvelope(AMarker, APass: String; AEnabled: Boolean);
var
lEnv: TROAESEncryptionEnvelope;
begin
lEnv := TROAESEncryptionEnvelope.Create(nil);
with lEnv do begin
Password := APass;
EnvelopeMarker := AMarker;
BeforeEnvelopeProcessed := DoBeforeEnvelopeProcessed;
end;
with TROMessageEnvelopeItem(ROMessage.Envelopes.Add) do begin
Envelope := lEnv;
Enabled := AEnabled;
end;
CheckListBox1.AddItem(GenerateString(lEnv),lEnv);
CheckListBox1.Checked[CheckListBox1.Count-1]:=AEnabled;
end;