I'm having trouble converting text to Base64 string in Java (Android) and .NET (Visual Basic). The plain (readable) form of ASCII characters convert fine. But when it comes to special characters (characters whose code is greater than 128), they're creating trouble for me.
For example I try converting a character code whose ASCII value is 65 (the character "A").
My Java code is:
char a = 65;
String c = String.valueOf(a);
byte bt[] = c.getBytes();
String result = Base64.encodeToString(bt, Base64.DEFAULT);
And my .NET code is:
Dim c As String = Chr(65)
Dim result as String = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(c))
These both return the same result: "QQ==". This is fine. But when I try converting a special character, for example a character code 153. Then it returns different results.
char a = 153;
String c = String.valueOf(a);
byte bt[] = c.getBytes();
String result = Base64.encodeToString(bt, Base64.DEFAULT);
This returns "wpk="
And my same .NET code:
Dim c As String = Chr(153)
Dim result as String = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(c))
This returns "4oSi"
This is so strange. What's wrong here. I'm using the native Base64 libraries on both platforms. Is something wrong with my code?