FaisalJ
April 17th, 2003, 02:25 AM
I am encrypting files. Teh brief code is:
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
// some code to set rsa skiped here
// input buffer
byte[] inbuf = new byte[(new FileInfo(fileName)).Length];
//output buffer
byte[] outbuf = null;
//stream
FileStream fs = File.OpenRead(fileName);
// read the file
fs.Read(inbuf,0, inbuf.Length);
fs.Close();
outbuf = rsa.Encrypt(inbuf,false);
//write to output file
fs = File.OpenWrite(outputFile);
fs.Write(outbuf,0,outbuf.Length);
fs.Close();
Now when the input file is a text file its works ok
but when thefile is a binay file (a Serialized file to be exact)
the outbuf = rsa.Encrypt(inbuf,false); crashes giving the error "bad length"
not that the binay file if opned in notpad has chracters like
Soo....whats wrong with length here ???
Thanks!
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
// some code to set rsa skiped here
// input buffer
byte[] inbuf = new byte[(new FileInfo(fileName)).Length];
//output buffer
byte[] outbuf = null;
//stream
FileStream fs = File.OpenRead(fileName);
// read the file
fs.Read(inbuf,0, inbuf.Length);
fs.Close();
outbuf = rsa.Encrypt(inbuf,false);
//write to output file
fs = File.OpenWrite(outputFile);
fs.Write(outbuf,0,outbuf.Length);
fs.Close();
Now when the input file is a text file its works ok
but when thefile is a binay file (a Serialized file to be exact)
the outbuf = rsa.Encrypt(inbuf,false); crashes giving the error "bad length"
not that the binay file if opned in notpad has chracters like
Soo....whats wrong with length here ???
Thanks!