Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
GeneralRe: Windows Form and Command Line Pin
Braincrash18-Feb-03 13:59
Braincrash18-Feb-03 13:59 
Generalchanging encryption password size Pin
jtmtv1817-Feb-03 15:22
jtmtv1817-Feb-03 15:22 
GeneralRe: changing encryption password size Pin
Furty17-Feb-03 17:01
Furty17-Feb-03 17:01 
GeneralRe: changing encryption password size Pin
jtmtv1817-Feb-03 19:31
jtmtv1817-Feb-03 19:31 
GeneralRe: changing encryption password size Pin
Furty18-Feb-03 9:40
Furty18-Feb-03 9:40 
GeneralRe: changing encryption password size Pin
jtmtv1818-Feb-03 12:10
jtmtv1818-Feb-03 12:10 
GeneralSecurity question Pin
Omega50117-Feb-03 13:30
Omega50117-Feb-03 13:30 
GeneralRe: Security question Pin
jtmtv1817-Feb-03 13:46
jtmtv1817-Feb-03 13:46 
this is what i use in my program to encrypt hole files. you can possibly use it for yours as well;

inName = full path of the file to be encrypted(this file is only opened and not deleted...you will have to rewrite that part)

outName : output...encrypted file

KeySecretString (the password to encrypt with)

to decrypt the file use the same code but replace :
CryptoStream encStream = new CryptoStream(fout, tdes.CreateEncryptor(tdes.Key, tdes.IV), CryptoStreamMode.Write);
with :
CryptoStream encStream = new CryptoStream(fout, tdes.CreateDecryptor(tdes.Key, tdes.IV), CryptoStreamMode.Write);

further more where you see the code DESCryptoServiceProvider des = new DESCryptoServiceProvider(); you can replace the DES part with RC2 to get RC2 encryption / decryption instead.

Happy Coding...

Jesse M
<br />
private void DecryptData(String inName, String outName, string KeySecretString)<br />
			 {  <br />
				    //Create the file streams to handle the input and output files.<br />
				    FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);<br />
				    FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);<br />
				    fout.SetLength(0);<br />
					string FileN = Path.GetFileName(outName);<br />
					InformationFile.Text = FileN;<br />
					InformationFile.Update();<br />
				    //Create variables to help with read and write.<br />
				    byte[] bin = new byte[buffersize]; //This is intermediate storage for the encryption.<br />
				    long rdlen = 0;              //This is the total number of bytes written.<br />
				    long totlen = fin.Length;    //This is the total length of the input file.<br />
				    int len;                     //This is the number of bytes to be written at a time.<br />
DESCryptoServiceProvider tdes = new DESCryptoServiceProvider(); <br />
					tdes.IV = ASCIIEncoding.ASCII.GetBytes(KeySecretString);			<br />
					tdes.Key =ASCIIEncoding.ASCII.GetBytes(KeySecretString);<br />
				    CryptoStream encStream = new CryptoStream(fout, tdes.CreateDecryptor(tdes.Key, tdes.IV), CryptoStreamMode.Write);        <br />
				    Console.WriteLine("Encrypting...");<br />
				    //Read from the input file, then encrypt and write to the output file.<br />
				    while(rdlen < totlen)<br />
				    {<br />
				        len = fin.Read(bin, 0, buffersize);<br />
				        encStream.Write(bin, 0, len);<br />
				        rdlen = rdlen + len;<br />
				        Console.WriteLine("{0} bytes processed", rdlen);<br />
<br />
				    }<br />
				   	fout.Flush();<br />
					fin.Flush();<br />
					encStream.Flush();<br />
				    encStream.Close();<br />
					fout.Close();<br />
					fin.Close();<br />
					return;<br />
				} <br />

The Code Project Is Your Friend...
GeneralRe: Security question Pin
Omega50117-Feb-03 14:07
Omega50117-Feb-03 14:07 
GeneralRe: Security question Pin
jtmtv1817-Feb-03 14:16
jtmtv1817-Feb-03 14:16 
GeneralRe: Security question Pin
Omega50117-Feb-03 15:21
Omega50117-Feb-03 15:21 
GeneralRe: Security question Pin
Furty17-Feb-03 16:55
Furty17-Feb-03 16:55 
GeneralReading Files From Offset Pin
afronaut17-Feb-03 13:19
afronaut17-Feb-03 13:19 
GeneralRe: Reading Files From Offset Pin
Xpander17-Feb-03 16:14
Xpander17-Feb-03 16:14 
GeneralRe: Reading Files From Offset Pin
Wesner Moise17-Feb-03 16:21
Wesner Moise17-Feb-03 16:21 
GeneralRe: Reading Files From Offset Pin
afronaut18-Feb-03 2:43
afronaut18-Feb-03 2:43 
GeneralRe: Reading Files From Offset Pin
Furty17-Feb-03 17:05
Furty17-Feb-03 17:05 
Questionprinting in .net problem? Pin
zhoujun17-Feb-03 13:13
zhoujun17-Feb-03 13:13 
GeneralMethod lock Pin
Filip Strugar17-Feb-03 12:55
Filip Strugar17-Feb-03 12:55 
GeneralRe: Method lock Pin
Wesner Moise17-Feb-03 16:03
Wesner Moise17-Feb-03 16:03 
QuestionHow do you use this DLL in C#? Pin
draco_iii17-Feb-03 9:43
draco_iii17-Feb-03 9:43 
AnswerRe: How do you use this DLL in C#? Pin
Anders Molin17-Feb-03 14:12
professionalAnders Molin17-Feb-03 14:12 
GeneraldotEASY Pin
Anonymous17-Feb-03 9:38
Anonymous17-Feb-03 9:38 
QuestionQ: How to Click a Button in Another Application Programatically in C#? Pin
Alwazeer17-Feb-03 7:28
Alwazeer17-Feb-03 7:28 
AnswerRe: Q: How to Click a Button in Another Application Programatically in C#? Pin
TigerNinja_17-Feb-03 7:55
TigerNinja_17-Feb-03 7:55 

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.