Re: HOW? Capture output stream as byte array

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 06/08/04


Date: Mon, 7 Jun 2004 18:18:48 -0500

Lee,
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
out.

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
Jay

"Lee Gillie" <ANTISPAMIFICATION_lee@odp.com> wrote in message
news:%2339IDWKTEHA.2480@TK2MSFTNGP10.phx.gbl...
> 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
>
>



Relevant Pages

  • Re: Data decryption issue
    ... MemoryStream memoryStream; ... CryptoStream cryptoStream; ... RijndaelManaged rijndael = new RijndaelManaged; ... of padding (the same as used to encrypt), I get an error that the padding is ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: HOW? Capture output stream as byte array
    ... An alternate option is to just pass a NetworkStream to the CryptoStream ... constructor instead of a memory stream. ... > My thought was a stateful call to my own Encrypt and Decrypt routines. ... > That I would pass a MemoryStream to the CryptoStream constructor. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: HOW? Capture output stream as byte array
    ... An alternate option is to just pass a NetworkStream to the CryptoStream ... constructor instead of a memory stream. ... > My thought was a stateful call to my own Encrypt and Decrypt routines. ... > That I would pass a MemoryStream to the CryptoStream constructor. ...
    (microsoft.public.dotnet.framework)
  • Re: HOW? Capture output stream as byte array
    ... An alternate option is to just pass a NetworkStream to the CryptoStream ... constructor instead of a memory stream. ... > My thought was a stateful call to my own Encrypt and Decrypt routines. ... > That I would pass a MemoryStream to the CryptoStream constructor. ...
    (microsoft.public.dotnet.security)
  • Re: HOW? Capture output stream as byte array
    ... If you are writing to a socket, why not just pass the NetworkStream itself ... I'm not so certain you need a MemoryStream, as I would simply pass the ... NetworkStream itself to the CryptoStream. ... > My thought was a stateful call to my own Encrypt and Decrypt routines. ...
    (microsoft.public.dotnet.framework)