www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - AES decrypt/encrypt Stream


I have to encrypt/decrypt all data which is sent through a stream 
(socketstream). The current design is:

TCP socket → SocketStream → EndianStream

Now I have to integrate some sort of AESStream:

TCP socket → SocketStream → AESStream → EndianStream

That is what I thought of, but there is one issue, I used to read just 
the parts I needed from the EndianStream, completly unbuffered, but when 
dealing with AES I have to buffer the data.

I thought of adding a BufferedStream and then en/decrypting the buffers, 
but I have no idea how you can do that. I also don't like to poll for 
data, read as many as possible and then encrypt it and write it into a 
temporary MemoryStream which has a EndianStream applied.

Any ideas how I can integrate AES en/decryption into my current design 
(TCP socket → SocketStream → EndianStream)?
Jul 30 2012