CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 5 of 5 FirstFirst ... 2345
Results 61 to 66 of 66
  1. #61
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: [RESOLVED] how can i encrypt a file?

    Quote Originally Posted by katy_price View Post
    so it reads, encrypts/ decrypts data in the input file and copies data 512 bytes at a time to the output file, when the data is less than the buffersize thats essentially the last read and copy right?
    Right.

    Note that the read operation in the copy-and-en/decrypt loop is done on the crypto stream that is "stacked on top" of the input file stream. The crypto stream then does read operations as needed on the input file stream itself. Not sure whether that was what you meant in your sentence I quoted.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  2. #62
    Join Date
    Nov 2010
    Posts
    139

    Re: [RESOLVED] how can i encrypt a file?

    sorry i don't get it.

    Code:
       // Process (i.e. encrypt or decrypt) data while copying from input file to output file:
    
      try {
        const int nBufferSize = 512;
        array<Byte> ^abBuffer = gcnew array<Byte>(nBufferSize);
        int nBytesRead;
    
        do {
          nBytesRead = cryptstream->Read(abBuffer, 0, nBufferSize);
          if (!nBytesRead) break;
          fOutput->Write(abBuffer, 0, nBytesRead);
        } while (nBytesRead == nBufferSize);
      }
      catch (...) {
        return false;
      }
    so the cryptstream encrytpts/decrypts the input file. the read() reads the file 512 bytes at a time, write() writes the 512 bytes to the output file.

  3. #63
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: [RESOLVED] how can i encrypt a file?

    Quote Originally Posted by katy_price View Post
    so the cryptstream encrytpts/decrypts the input file. the read() reads the file 512 bytes at a time, write() writes the 512 bytes to the output file.
    More or less, yes. The only tricky part is that the read actually reads from the cryptstream that in turn reads from the input file. (And it does that on its own, so we don't have code for that.)
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  4. #64
    Join Date
    Nov 2010
    Posts
    139

    Re: [RESOLVED] how can i encrypt a file?

    Quote Originally Posted by Eri523 View Post
    More or less, yes. The only tricky part is that the read actually reads from the cryptstream that in turn reads from the input file. (And it does that on its own, so we don't have code for that.)
    so the cryptostream reads and moves data through the cryto process in the input file, then the read() reads from the Cryptostream 512 bytes....
    sorry how does the buffer work - sorry i no you used a do while loop but what is the buffer for
    Last edited by katy_price; January 20th, 2011 at 04:38 PM.

  5. #65
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: [RESOLVED] how can i encrypt a file?

    Quote Originally Posted by katy_price View Post
    sorry how does the buffer work
    You mean this one?

    Code:
        array<Byte> ^abBuffer = gcnew array<Byte>(nBufferSize);
    It's a plain array of bytes where bytes get read into and written back out from there. It doesn't do anything on its own.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  6. #66
    Join Date
    Nov 2010
    Posts
    139

    Re: [RESOLVED] how can i encrypt a file?

    thank you

Page 5 of 5 FirstFirst ... 2345

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured