Cmonkey123
Wanderer
Encryption Troubles
[edit]
Actually I'm having problems with decryption...
In the "rewrite file with decrypted data" section at the end of the method there's some kind of problem with the writing of the data into the file. When I run the program, it gives me the exception:
How am I supposed rewrite the decrypted data into the file?
[edit]
Actually I'm having problems with decryption...
Code:
public static void DecryptRewrite( string FilePath )
{
string filedata;
//create streams
System.IO.FileStream decryptfile;
System.IO.StreamReader readfile;
System.Security.Cryptography.CryptoStream cstream;
//create crypto
DESCryptoServiceProvider cryptic = new DESCryptoServiceProvider();
//create key
cryptic.Key = ASCIIEncoding.ASCII.GetBytes( "xxxxxxxx" );
cryptic.IV = cryptic.IV = ASCIIEncoding.ASCII.GetBytes( "xxxxxxxx" );
//open file to be decrypted
decryptfile = new FileStream( FilePath, FileMode.Open, FileAccess.Read );
//decrypt decryptfile
cstream = new CryptoStream( decryptfile, cryptic.CreateDecryptor(), CryptoStreamMode.Read );
//read file data and store in data string
readfile = new StreamReader( FilePath );
filedata = readfile.ReadToEnd();
byte[] data = ASCIIEncoding.ASCII.GetBytes( filedata );
//close streams
readfile.Close();
cstream.Close();
//rewrite file with decrypted data
System.IO.FileStream rewritefile = new FileStream( FilePath, FileMode.OpenOrCreate, FileAccess.Write );
rewritefile.Write( data, 0, data.Length );
rewritefile.Close();
}
In the "rewrite file with decrypted data" section at the end of the method there's some kind of problem with the writing of the data into the file. When I run the program, it gives me the exception:
An unhandled exception of type 'System.NotSupportedException' occurred in mscorlib.dll
Additional information: Stream does not support writing.
How am I supposed rewrite the decrypted data into the file?