Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I haved similar problem before so sorry if I should just write it there instead of creating new topic.
You adviced me in my question about encoding and decoding from file and to file this:
C#
public static string encode(string text)
{
    byte[] mybyte = System.Text.Encoding.UTF8.GetBytes(text);
    string returntext = System.Convert.ToBase64String(mybyte);
    return returntext;
}

public static string decode(string text)
{
    byte[] mybyte = System.Convert.FromBase64String(text);
    string returntext = System.Text.Encoding.UTF8.GetString(mybyte);
    return returntext;
}

(while someone unrecommended me using UTF-8 :D)but now it seems it doesn't work when I want to encode/decode from text file with more than two lines. Is that code bad?
Posted
Comments
Andreas Gieriet 27-Feb-12 18:39pm    
What exactly means "[...] doesn't work [...]"? Can you please give more details?

When I compile this, all works fine, i.e. the original --> encode --> decode --> original is given, no mather how many newlines I add to the text...
Sergey Alexandrovich Kryukov 27-Feb-12 19:17pm    
I can't believe that. Something wrong could be outside this code. You also work with files; the problem could be there. So, could you make a code sample covering whole workflow, for example, Unicode text file all the way to base64 file and all the way back?
--SA
LosEagle 28-Feb-12 2:16am    
Doesn't work means that when I'am using decoder to decode encoded text in the text file I get back Base-64 char array error. When I used some browser based encoders/decoders and gived there content of text file it just didn't taked before I deleted the lines to have only 2 lines. So I think this is the reason why it doesn't work. (Sorry for late answer when I was writing this topic it was midnight in Czech)

That depends on the code that is reading the file and calling the code you posted in this question.

The only reasons I can think of that it only works with one line of your file is because you only read one line of the original file and/or you read multiple lines (and got an array of strings) and you only passed the first string to this code.
 
Share this answer
 
Ok, sorry guys. Seems like the problem was bad input variable in calling decryption.. well this is embarassing. Thanks for your helping
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900