<"Ondrej Sevecek" <ondra_at_sevecek_dt_com>> wrote:
Hello,
would you please provide me with some simple sample of how to use the
DESCryptoServiceProvider to encrypt a buffer
byte[] buffer;
with key
byte[] key;
produceing cipher text:
byte[] ciphertext;
I saw some sample using Streams, but is there a simpler method working for
buffers?
You need to use a stream at some stage, but using MemoryStream and its
ToArray method make it easy to return a byte array.
Basically, just create a MemoryStream, then an appropriate CryptoStream
to write into that. Write your original buffer into the CryptoStream,
close it (which will do the appropriate FlushFinalBlock - just
disposing of it won't, due to a bug in 1.1), and then call ToArray on
the MemoryStream.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too