Note that XOR is going to be incredibly easy to break if the other end knows anything about the original data. If it knows the correct 8 bytes at any position, your "encryption" is immediately broken. Are you really sure you want to do this? Coming up with your own encryption scheme is almost always a bad idea - is there any reason you don't want to use one of the many encryption algorithms built into the framework? Sure, use a hardware dongle to derive the key - but then use a normal CryptoStream
.
However, if you really want to do this, there are two obvious options:
Build a stream wrapper, yes. Unless you really need to support the async operations, I wouldn't do so - it'll make things tougher. Write a stream implementation which takes another stream to proxy to as well as the long
value to XOR with, and then whenever you read or write data, apply the XOR.
Build an implementation of ICryptoTransform
. Then you can potentially get CryptoStream
to do all the heavy lifting in terms of the stream stuff - you just need to know how to transform a block at a time. I believe this should be pretty simple, but I can't say I've ever done it myself.