Allahmuad Abu Zhar
Member
So i have this chat application that i want to encode the chat using base64. I got it working with the encoding but it fails on the decoding. First, it encodes the string of a textbox and sends it to the database, then i have a timer that gets the content of the db to a listbox. Now i have a for each loop to loop trough all items and decode the string of the item, remove the current item, then add the decoded string. And here it fails.
Here is the encoding and decoding code:
here is the for each loop:
now this is the error i get:
Input is not a valid Base-64 string because it contains a character that has not been Base - 64 format , more than two fill characters or invalid characters other than a space character .
( translated from swedish to english )
by the way, the chat log ( mysql table ) for the listbox is clear.
Here is the encoding and decoding code:
VB.NET:
encode function[COLOR=#000000][FONT=Roboto]
[/FONT][/COLOR] Public Function encode(ByVal str As String) As String
Dim bytesToEncode As Byte()
bytesToEncode = Encoding.UTF8.GetBytes(str)
Dim encodedText As String
encodedText = Convert.ToBase64String(bytesToEncode)
Return encodedText
End Function
'decode function
Public Function decode(ByVal str As String) As String
Dim decodedBytes As Byte()
decodedBytes = Convert.FromBase64String(str)
Dim decodedText As String
decodedText = Encoding.UTF8.GetString(decodedBytes)
Return decodedText
End Function
here is the for each loop:
VB.NET:
For Each i As String In chatlist.Items
chatlist.Items.Remove(i)
chatlist.Items.Add(decode(i))
Next
now this is the error i get:
Input is not a valid Base-64 string because it contains a character that has not been Base - 64 format , more than two fill characters or invalid characters other than a space character .
( translated from swedish to english )
by the way, the chat log ( mysql table ) for the listbox is clear.