My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
MessageEncryption  
Encrypting and decrypting messages
Featured, Phase-Implementation
Updated Nov 6, 2011 by lidg...@gmail.com

Message encryption

Messages can be encrypted using the Xtea, or other algorithms. This is done like this:

INetEncryption algo = new NetXtea("TopSecret");

NetOutgoingMessage msg = client.CreateMessage();
msg.Write("Some content");
msg.Write(42);
msg.Encrypt(algo);

Notice that encryption must be done last and that after encryption no more data should be written to the message.

Decrypting the message on arrival is done like this:

INetEncryption algo = new NetXtea("TopSecret");

incomingMessage.Decrypt(algo);

The algorithm instance can be reused over the application lifetime, but it is not thread safe; so you'll have to create an instance per thread if you're encrypting/decrypting on more than one thread.

Note that this feature does not concern itself with synchronizing the password between hosts and it only encrypts the content of the message, not message headers.

Currently Xtea, AES, DES, Triple DES, RC2 and a simple XOR algorithm are implemented; it's easy to extend; any class implementing the INetEncryption can be used. For block level algorithms there is a base class, NetBlockEncryption, that can be used to simplify such ciphers - you will only need to provide implementations for EncryptBlock, DecryptBlock and BlockSize.

Comment by cameron....@gmail.com, Oct 16, 2011

This is awesome!

Comment by charlie2...@gmail.com, Feb 19, 2012

Which of the available encryption methods is the fastest?


Sign in to add a comment
Powered by Google Project Hosting