I am having a problem converting strings with "extended" characters to an Encryptable byte array.
...
Sub Globals
Dim conv As ByteConverter
End Sub
Sub Activity_Create(FirstTime As Boolean)
conv.LittleEndian = True
Dim PaddedString As String = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnoá "
Log("padddestring " & PaddedString.Length & " >" & PaddedString & "<")
Dim data() As Byte = conv.StringToBytes(PaddedString, "UTF8")
Log("Data Len before " & data.Length)
If data.Length mod 8 <> 0 Then
Dim tmpdata(PaddedString.Length) As Byte
Log("data len " & data.Length)
conv.ArrayCopy(data,0,tmpdata,0,PaddedString.Length-1)
data = tmpdata
End If
Log("Data after: " & data.Length)
End Sub
...
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.example
** Service (starter) Create **
** Service (starter) Start **
** Service (widgetservice) Start **
** Activity (main) Create, isFirst = true **
padddestring 48 >abcdefghijklmnopqrstuvwxyzabcdefghijklmnoá <
Data Len before 49
data len 49
Data after: 48
In order to encrypt data it must be multiples of 8 bytes (I believe).
When I convert a string of standard ascii characters of 48 bytes to a byte array, it returns a 48 byte array.
When I convert a string of ascii characters with, for example "á" embedded within, it returns a 49 byte array. Each additional "á" (extended character) results in one additional byte added to the array, which in return causes the byte array to fail encryption (because it is not a 8 byte multiple in size).
What is the rule on these "extended characters" when the byte converter converts them to bytes?
and how can I insure the byte array is a multiple of 8 bytes in size?
Thanks,
Rusty