Click here to Skip to main content
15,921,622 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
My code is for encryption and decryption of url.
But in decryption an error occurs in convert.from64BaseString(strinput), because it fails to convert '+' and '/' .

How can I convert '+'and '/' char in byte, without using convert.from64BaseString() ?
Posted
Updated 20-Feb-11 1:02am
v2

What is the error? It should not fail to convert either character, they are both in teh default base64 character set: http://en.wikipedia.org/wiki/Base64[^]
When I try, it works fine:
C#
string unicode = "ABCDEFG+/abcedfg";
byte[] ascii = System.Text.Encoding.ASCII.GetBytes(unicode);
string base64 = Convert.ToBase64String(ascii);
byte[] convertBack = Convert.FromBase64String(base64);
string regenerated = System.Text.Encoding.ASCII.GetString(convertBack);
Console.WriteLine(unicode);
Console.WriteLine(regenerated);

How is your code different?
 
Share this answer
 
Comments
Espen Harlinn 20-Feb-11 7:38am    
My 5, nice, simple and correct :)
Sergey Alexandrovich Kryukov 20-Feb-11 15:10pm    
Agree, my 5, too.
--SA
Hi

I think you have misunderstood your problem. I have seen your question before.

Your problem is not converting, your problem is passing the string as a url QueryString.

the char '+' will not be passed as query string, you will get a blank space. So you need to replace it with other char (before appending the query string), for example replace + with @ and execute the link (may be you need to chk your string already having a @, replace with a char which is not already in the string, may be the replace char also can be passed as a parameter in the querystring). In the target page you may need to replace the @ with the + . So you will get the original string and then you can convert and compare.
 
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