Encrypted streams

Does Julia already have a library which can encrypt streams with a symmetric key? What I need is something simple as:

using Sockets

server = listen()
socket = accept(server)
# Some arbitrary key exchange protocol. For example,
# key = Diffie-Hofman key exchange with signatures
securesocket = SecureIO(socket,key)

As there is already a Nettle.jl package which has symmetric encryption and hashing functions it should be easy to implement one. But how can I implement a stream type in Julia?

Not sure if this would meet your needs, or be too much setup. But I’m assuming you want the stream encrypted because it’s going over an unsecure network. But you could could look at the WebSockets package, which would basically give you a TCP/IP stream where the server can be placed behind an apache or nginx reverse proxy. You would configure the proxy for https and the data would be encrypted. One advantage is that you can be pretty sure of the encryption used by apache and nginx.

I do have a specific requirements on who can participate in Diffie-Hofman key exchange thus I really need to encrypt an usecure stream. I have rather weak security requirements for the protocol I try to implement. There encryption is only needed to prevent third party to poison the protocol and make it unfeasible.

Additionally I would like to implement customized onion protocol where the ability of encrypting streams is essential.

Since currently there does not seem to be such a library I am now looking into writing one myself. I don’t understand how to work with streams, and I wonder if it is possible to separate them into input and output channel easily. And if it is possible to construct a stream from channels. For example, then I could do:

server = listen()
socket = accept(server)
inputch, outputch = seperateio(socket)
newinputch, newoutputch = f(inputch), g(outputch)
newstream = Stream(inputch,outputch)

seperateio I could implement myself quite easily. But how could I construct a stream from channels which I could then pass for example to Serializer?