Trying to encrypt a file transer

mwaite

Member
Licensed User
Hi all,

OK I give up. I have spent way too much time trying to figure this one out...

I created a file download service running between two B4P apps, one pda/client the other a xp/server. I have no problem with the file transers working smoothly (based on code examples using the BinaryFile lib).

Now I'd like to encrypt the data for protection. I have been able to figure out how to encrypt handshaking data packets between client and server using the HTTP lib GetStream, but for the life of me I can't get the encryption structure figured out on a binary file transfer using WriteBytes2.

What I have kinda figured out:
1. Reading a file:
count = fileStream.ReadBytes(buffer(),8192) ' to read the 1st 8K packet

2. Encrypting the buffer:
count2() = Crypto.Encrypt(ED, buffer()) ' to encrypt the count packet above

I read 8192 instead of 8200 because (I think) crypto is adding 8 bytes to the buffer.

3. Sending the encrypted buffer:
newcount = ArrayLen(count2)
Do While newcount > 0
fileStream1.WriteBytes2(me(),0,newcount)
size = size - count << where size = fileStream.Length ... << another problem is the ending 8K packet will be of unknown size.

Even trying to decode just a single 8K packet (without worrying about subsequent packets) I keep getting "Bad Data" errors from Decrypt. Obviously my strutures aren't matching between the encrypted buffer and the decrypted, but I've been wracking my head and it really hurts now! :sign0148::sign0148:

I'd be forever greatfull on any guidance!!
 

mwaite

Member
Licensed User
I started with that line of thought to begin with. The client can select any available file on the server, which could be megs/tensofmegs or even larger. So I thought if I broke the encryption up into smaller packets then the amount of time it took to encrypt a single packet would be negligable compared to the file transfer speed.
 

mwaite

Member
Licensed User
Ouch, that even makes it worse then... So perhaps I can ask a better question... If you want to be able to transfer any filesize file, encrypted, over a network connection, what would be the least painfull method? :confused:
 

mwaite

Member
Licensed User
Hi Erel,

OK I've been working on that approach but I guess I'm misunderstanding something. I still have the problem of parsing the file into manageable segments, which becomes an issue with unknown encryption buffer lengths, right? Due to the potential for files larger than the PDA's memory, I don't think I can load the entire file in a buffer for encryption all at once.
 

mwaite

Member
Licensed User
Fantastic!! :sign0060:

Thank you very much Erel!!
 
Top