stavesacre
Member
- Joined
- Dec 5, 2003
- Messages
- 6
I am having trouble sending (receiving?) a file over an encrypted networkstream. Here is my send/receive code. The program does not appear to be either sending or receiving the file, not sure which. Any thoughts!??! This is a major headache, cause it seems as if im just missing something simple. Let me know if you need any more information....or maybe if theres a better method.
Thank-you in advance!
public void sendFile(String fileName, Stream networkStream)
{
FileStream fin = new FileStream(fileName,FileMode.Open, FileAccess.Read);
byte[] bin = new byte[100];
long rdlen = 0;
long totlen = fin.Length;
int len;
CryptoStream encStream = new CryptoStream(networkStream, tripleDES.CreateEncryptor(), CryptoStreamMode.Write);
Console.WriteLine("Encrypting...");
while(rdlen < totlen)
{
len = fin.Read(bin, 0, 100);
encStream.Write(bin, 0, len);
rdlen = rdlen + len;
Console.WriteLine("{0} bytes processed", rdlen);
}
encStream.Close();
}
---
public void receiveFile(FileStream fs, NetworkStream ns)
{
byte[] bin = new byte[100];
long rdlen = 0;
int len = 100;
CryptoStream decStream = new CryptoStream(fs, tripleDES.CreateDecryptor(), CryptoStreamMode.Write);
Console.WriteLine("Decrypting...");
while(ns.DataAvailable)
{
len = ns.Read(bin, 0, 100);
decStream.Write(bin, 0, len);
rdlen = rdlen + len;
Console.WriteLine("{0} bytes processed", rdlen);
}
decStream.Close();
}
Thank-you in advance!
public void sendFile(String fileName, Stream networkStream)
{
FileStream fin = new FileStream(fileName,FileMode.Open, FileAccess.Read);
byte[] bin = new byte[100];
long rdlen = 0;
long totlen = fin.Length;
int len;
CryptoStream encStream = new CryptoStream(networkStream, tripleDES.CreateEncryptor(), CryptoStreamMode.Write);
Console.WriteLine("Encrypting...");
while(rdlen < totlen)
{
len = fin.Read(bin, 0, 100);
encStream.Write(bin, 0, len);
rdlen = rdlen + len;
Console.WriteLine("{0} bytes processed", rdlen);
}
encStream.Close();
}
---
public void receiveFile(FileStream fs, NetworkStream ns)
{
byte[] bin = new byte[100];
long rdlen = 0;
int len = 100;
CryptoStream decStream = new CryptoStream(fs, tripleDES.CreateDecryptor(), CryptoStreamMode.Write);
Console.WriteLine("Decrypting...");
while(ns.DataAvailable)
{
len = ns.Read(bin, 0, 100);
decStream.Write(bin, 0, len);
rdlen = rdlen + len;
Console.WriteLine("{0} bytes processed", rdlen);
}
decStream.Close();
}