Click here to Skip to main content
15,912,756 members
Home / Discussions / C#
   

C#

 
GeneralRe: Some kind of file encryption thingy!! Pin
Colin Angus Mackay25-Feb-05 11:51
Colin Angus Mackay25-Feb-05 11:51 
GeneralRe: Some kind of file encryption thingy!! Pin
Anthony Mushrow25-Feb-05 12:22
professionalAnthony Mushrow25-Feb-05 12:22 
GeneralRe: Some kind of file encryption thingy!! Pin
mav.northwind26-Feb-05 0:41
mav.northwind26-Feb-05 0:41 
GeneralProblem Get Attribute Returning Null. Pin
DemonBob25-Feb-05 11:19
DemonBob25-Feb-05 11:19 
GeneralRe: Problem Get Attribute Returning Null. Pin
Colin Angus Mackay25-Feb-05 11:49
Colin Angus Mackay25-Feb-05 11:49 
GeneralRe: Problem Get Attribute Returning Null. Pin
DemonBob25-Feb-05 15:16
DemonBob25-Feb-05 15:16 
GeneralEncrypting and Decrypting a file Pin
Peter Nirschl25-Feb-05 9:27
Peter Nirschl25-Feb-05 9:27 
GeneralRe: Encrypting and Decrypting a file Pin
Rei Miyasaka25-Feb-05 11:46
Rei Miyasaka25-Feb-05 11:46 
Actually, the encrypt function will work with any file type, but the decrypt function might not. StreamReader and StreamWriter are to help with reading/writing text from/to streams, so you don't want to use them in this case.

The example code there isn't very efficient for large files either, since it reads in the whole file at once, and your memory will be stuffed.

Here's a more practical version of the last section of the EncryptFile function:
<br />
			byte[] buffer = new byte[1024];<br />
			int len;<br />
<br />
			//Read in a maximum of 1 kilobyte from the file at a time, while there are more than 0 bytes left.<br />
			while((len = fsInput.Read(buffer, 0, buffer.Length)) != 0)<br />
			{<br />
				//Write the contents of the current buffer to the crypt stream<br />
				cryptostream.Write(buffer, 0, len);<br />
			}<br />
			cryptostream.Close();<br />
			fsInput.Close();<br />
			fsEncrypted.Close();<br />


And here's the last 5 lines of the DecryptFile function, works for any file type and file size:
<br />
			//Print the contents of the decrypted file.<br />
			byte[] buffer = new byte[1024];<br />
			int len;<br />
			FileStream fsDecrypted = new FileStream(sOutputFilename, FileMode.Create);<br />
			//Read in a maximum of 1 kilobyte at a time, while there are more than 0 bytes left<br />
			while((len = cryptostreamDecr.Read(buffer, 0, buffer.Length)) != 0)<br />
			{<br />
				//Write the contents of the decrypted buffer to the output file stream<br />
				fsDecrypted.Write(buffer, 0, len);<br />
			}<br />

GeneralRe: Encrypting and Decrypting a file Pin
Peter Nirschl25-Feb-05 22:09
Peter Nirschl25-Feb-05 22:09 
GeneralRe: Encrypting and Decrypting a file Pin
Rei Miyasaka25-Feb-05 22:13
Rei Miyasaka25-Feb-05 22:13 
GeneralIncorrect syntax near keyword 'DEFAULT' Pin
Mark T Garcia25-Feb-05 8:20
Mark T Garcia25-Feb-05 8:20 
GeneralRe: Incorrect syntax near keyword 'DEFAULT' Pin
Radgar25-Feb-05 8:33
Radgar25-Feb-05 8:33 
GeneralRe: Incorrect syntax near keyword 'DEFAULT' Pin
Mark T Garcia25-Feb-05 9:12
Mark T Garcia25-Feb-05 9:12 
GeneralRe: Incorrect syntax near keyword 'DEFAULT' Pin
Radgar25-Feb-05 9:41
Radgar25-Feb-05 9:41 
GeneralRe: Incorrect syntax near keyword 'DEFAULT' Pin
Mark T Garcia25-Feb-05 11:53
Mark T Garcia25-Feb-05 11:53 
GeneralRe: Incorrect syntax near keyword 'DEFAULT' Pin
Dave Kreskowiak25-Feb-05 9:45
mveDave Kreskowiak25-Feb-05 9:45 
GeneralRe: Incorrect syntax near keyword 'DEFAULT' Pin
Mark T Garcia25-Feb-05 11:47
Mark T Garcia25-Feb-05 11:47 
GeneralRe: Incorrect syntax near keyword 'DEFAULT' Pin
Dave Kreskowiak25-Feb-05 13:08
mveDave Kreskowiak25-Feb-05 13:08 
GeneralRe: Incorrect syntax near keyword 'DEFAULT' Pin
Mark T Garcia25-Feb-05 13:30
Mark T Garcia25-Feb-05 13:30 
GeneralWindows Form and Message Box Pin
MarkMokris25-Feb-05 7:51
MarkMokris25-Feb-05 7:51 
GeneralRe: Windows Form and Message Box Pin
Peter Nirschl25-Feb-05 9:31
Peter Nirschl25-Feb-05 9:31 
GeneralRe: Windows Form and Message Box Pin
DougW4825-Feb-05 14:04
DougW4825-Feb-05 14:04 
GeneralRe: Windows Form and Message Box Pin
leppie25-Feb-05 19:24
leppie25-Feb-05 19:24 
GeneralXmlValidingReader getting started Pin
Kenny O'Dell25-Feb-05 7:50
Kenny O'Dell25-Feb-05 7:50 
GeneralRe: XmlValidingReader getting started Pin
Kenny O'Dell25-Feb-05 7:53
Kenny O'Dell25-Feb-05 7:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.