Re: HOW? Capture output stream as byte array
From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: Mon, 7 Jun 2004 18:18:48 -0500
In addition to the other comments.
If you are writing to a socket, why not just pass the NetworkStream itself
to the CryptoStream class?
You can use MemoryStream.GetBuffer & MemoryStream.ToArray to get the bytes
I believe you can use MemoryStream.SetLength to reset the memory stream.
(based on reading the help, I have not tried it). However I would simply use
a new MemoryStream object each time I needed one.
I'm not so certain you need a MemoryStream, as I would simply pass the
NetworkStream itself to the CryptoStream.
Hope this helps
"Lee Gillie" <ANTISPAMIFICATION_lee@odp.com> wrote in message
> I am using Cryptography. You can encrypt or decrypt by providing an
> output stream as a parameter to the CryptoStream constructor. But I
> need byte arrays, as I am encrypting on the fly to a socket, and need
> to manage all socket traffic.
> My thought was a stateful call to my own Encrypt and Decrypt routines.
> That I would pass a MemoryStream to the CryptoStream constructor. But
> it appears that for each write CryptoStream does to my memory stream,
> there is no way for me to get the bytes out of the MemoryStream and
> and reset the MemoryStream content, so that its byte content does not
> continue to grow. The files being encrypted, for example, might be as
> large as 100MB. I could encrypt entirely to YATDF (yet another
> temporary disk file), and the pass that to the socket. But if there
> is a way, I would like to avoid a disk file.
> Maybe MemoryStream is NOT the right object, because I don't see how to
> do the above. Is there some other stream object, or perhaps, a way to
> do what I want with MemoryStream?
> TIA - best regards, Lee Gillie