Re: [RESOLVED] how can i encrypt a file?
Quote:
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.
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.
Re: [RESOLVED] how can i encrypt a file?
Quote:
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.)
Re: [RESOLVED] how can i encrypt a file?
Quote:
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
Re: [RESOLVED] how can i encrypt a file?
Quote:
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.
Re: [RESOLVED] how can i encrypt a file?