By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,854 Members | 869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,854 IT Pros & Developers. It's quick & easy.

DESCryptoServiceProvider

P: n/a
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?

O.

Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
<"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
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.