|
-
January 20th, 2011, 01:11 PM
#61
Re: [RESOLVED] how can i encrypt a file?
 Originally Posted by katy_price
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.
-
January 20th, 2011, 02:39 PM
#62
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.
-
January 20th, 2011, 03:29 PM
#63
Re: [RESOLVED] how can i encrypt a file?
 Originally Posted by katy_price
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.
-
January 20th, 2011, 04:02 PM
#64
Re: [RESOLVED] how can i encrypt a file?
 Originally Posted by Eri523
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.
-
January 20th, 2011, 04:33 PM
#65
Re: [RESOLVED] how can i encrypt a file?
 Originally Posted by katy_price
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.
-
January 20th, 2011, 07:14 PM
#66
Re: [RESOLVED] how can i encrypt a file?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|