Can someone explain why this give 2 different strings in the TextAreas please.
Encrypted() As Byte. This Ubound is 31 and the first 4 elements are:128, 152, 201, 135
Dim L As Integer = Ubound(Encrypted)
Dim mb As MemoryBlock
Dim sTemp As String
For c As Integer = 0 to L
Dim num As Integer = Encrypted(c)
sTemp = sTemp + Encodings.UTF16.Chr(num)
mb(c) = Encrypted(c)
Next
TextArea1.Text = sTemp //Also tried DefineEncoding(sTemp, Encodings.UTF16)
TextArea2.Text = mb //DefineEncoding(mb, Encodings.UTF16)
TextArea1.Text with sTemp
???3
t w ?j,??o`?
TextArea2 with mb
ɇ͟3
t w j,o`
TextArea2 with DefineEncoding(mb, Encodings.UTF16)
???
dim encrypted() as integer = array(128, 152, 201, 135)
Dim L As Integer = Ubound(Encrypted)
Dim mb As new MemoryBlock(8)
Dim sTemp As String
For c As Integer = 0 to L
Dim num As Integer = Encrypted(c)
sTemp = sTemp + Encodings.UTF16.Chr(num)
mb.Int16Value(c*2) = Encrypted(c)
Next
TextArea1.Text = sTemp //Also tried DefineEncoding(sTemp, Encodings.UTF16)
TextArea2.Text = DefineEncoding(mb, Encodings.UTF16)
[quote=295434:@Jym Morton]Thanks, yes I have it showing both the same now. So if I have L as the Length of the Encrypted then
mb = New MemoryBlock (L*2) ?
[/quote]
Seems about right if encoded is an array of bytes
[quote=295434:@Jym Morton]So the next question would be when I read that back into a MemoryBlock why is the MemoryBlock size 48?
Dim mb As MemoryBlock = DefineEncoding(TextArea1.Text, Encodings.UTF16)
now mb.Size = 48.[/quote]
Why are you using define encoding when reading it from the text area ?
That makes no sense
You MIGHT use CONVERT encoding - text areas dont display raw unencoded bytes - the data is ALWAYS in some well known encoding
I don’t know what you want to achieve eventually, but you may want to investigate the new framework MemoryBlock and MutableMemoryBlock, as well as the new Text data type.
None of the issues you encounter would be possible with these.
Thanks Michel, I just made a class to encrypt\decrypt using the AES algorithm. (for learning) it works fine as long as I stay with UTF8. I was trying to make it UTF16 but I’m giving up