-
July 7th, 2009, 08:41 AM
#1
binary file sent from windows -> linux help needed
Hello,
I am sending an encrypted binary file over tcp/ip form windows to linux. When I get into linux and try to run mcrypt to decrypt the file I get "wrong key" error. I am wondering somehow if the file is being corrupted because of the different platforms? Here are some facts I do know:
1. This works with the exact same code windows->windows
2. My file where I write the binary form the tcp/ip stream looks like this:
void StringToFile(string msg, string file)
{
ofstream ofs(file.c_str(), ofstream::binary);
ofs.clear();
ofs.write(msg.data(), message.size());
ofs.close();
}
Can anyone help?
Regards,
Ellay K.
-
July 7th, 2009, 08:51 AM
#2
Re: binary file sent from windows -> linux help needed
Is that actual code or did you just type it in ? The reason I am asking:
Code:
ofs.write(msg.data(), message.size());
-
July 7th, 2009, 09:16 AM
#3
Re: binary file sent from windows -> linux help needed
I just typed it in.. that is a typo.. the actual code is:
ofs.write(msg.data(), msg.size());
Thanks..; any idea what might be going wrong?
Regards,
Ellay K.
-
July 7th, 2009, 09:20 AM
#4
Re: binary file sent from windows -> linux help needed
One additional piece of information.. this is how I write files to strings:
Code:
string WriteFileToString(string filename)
{
ifstream infile(filename.c_str(), ifstream::binary);
infile.seekg(0,ios::end);
size_t length = infile.tellg();
infile.seekg(0, ios::beg);
string message(length, 0);
copy(istreambuf_iterator<char>(infile), istreambuf_iterator<char>(), message.begin());
return message;
}
I am wondering if the line return difference between unix and windows is my problem? I dont know how to fix that.
Regards,
Ellay K.
-
July 7th, 2009, 10:29 AM
#5
Re: binary file sent from windows -> linux help needed
Another interesting piece of information. If I write the message in the code like this:
Code:
string msg="<?xml version=\"1.0\" encoding=\"UTF-8\"?> <Status> <Time>1246650079</Time> <Msg_ID>73</Msg_ID> <Name>Testing </Name>";
it works both windows->windows and windows->linux
however if I write it like this:
Code:
string msg="<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
<Status> \
<Time>1246650079</Time> \
<Msg_ID>73</Msg_ID> \
<Name>Testing </Name>";
It only works windows->windows and not windows to linux.
-
July 7th, 2009, 10:53 AM
#6
Re: binary file sent from windows -> linux help needed
It also seems to work with linux with less than 170 characters.. more than 170 characters it crashes.. can anyone help me?
Regards,
Ellay K.
-
July 7th, 2009, 11:20 AM
#7
Re: binary file sent from windows -> linux help needed
The most common reason why using multiple lines would cause a problem is differing newline conventions between the platforms. However, if you're opening all your files (for reading and writing) in binary mode, that shouldn't be a problem.....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|