|
I'm developing ftp application in c# winform framework 3.5 visual studio 2008.
algorithm im using for encryption is "RijndaelManaged" but in decryption getting error.
i scheduling time it automatically uploads all files from specific directory(client system) to FTP server, pls suggests me which algorithm is used for ftp in c#...
here is my code.
public static void EncryptFile(string inputFile, string outputFile, string skey)
{
RijndaelManaged aes = new RijndaelManaged();
try
{
byte[] key = ASCIIEncoding.UTF8.GetBytes(skey);
using (FileStream fsCrypt = new FileStream(outputFile, FileMode.Create))
{
using (CryptoStream cs = new CryptoStream(fsCrypt, aes.CreateEncryptor(key, key), CryptoStreamMode.Write))
{
using (FileStream fsIn = new FileStream(inputFile, FileMode.Open))
{
int data;
while ((data = fsIn.ReadByte()) != -1)
{
cs.WriteByte((byte)data);
}
aes.Clear();
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
aes.Clear();
}
}
private static void DecryptFile(string inputFile, string outputFile, string skey)
{
RijndaelManaged aes = new RijndaelManaged();
try
{
byte[] key = ASCIIEncoding.UTF8.GetBytes(skey);
using (FileStream fsCrypt = new FileStream(inputFile, FileMode.Open))
{
using (FileStream fsOut = new FileStream(outputFile, FileMode.Create))
{
using (CryptoStream cs = new CryptoStream(fsCrypt, aes.CreateDecryptor(key, key), CryptoStreamMode.Read))
{
int data;
while ((data = cs.ReadByte()) != -1)
{
fsOut.WriteByte((byte)data);
}
aes.Clear();
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
aes.Clear();
}
}
|
|
|
|
|
..
}
catch (UnclearQuestionException uqex)
{
MessageBox.Show("Your question is not clear. Please tell us more about the exception you see!");
}
|
|
|
|
|
Member 8653959 wrote: pls suggests me which algorithm is used for ftp in c#...
There's no algorithm, FTP is a protocol. It works with bytes, and cares little about it's contents.
I suggest you divide this into two separate problems; encrypting/decrypting a local file, and uploading/downloading a file. Once both problems are solved, combine them.
|
|
|
|
|
yup - that'd be the way .. I love it when someone comes to me and says 'my program does this and this and this but doesnt work' ... and I reply 'a) define doesnt work and b) does each of those seperate parts work independently before you try and put them together, hmmmm ?' - admittedly, I need to learn more about unit testing with frameworks, but I usually do a better job
'g'
|
|
|
|