Question How to write non-ascii characters on maskedTextBox?

Excaliburr

New member
Joined
Dec 2, 2020
Messages
1
Programming Experience
1-3
I'm using TripleDESCryptoService and I keep the encrypted text in byte[]. I want to display this on a textBox. So I choose AsciiOnly = False for maskedTextBox. Now I copy a non-ascii character and paste it on maskedTextBox and there is no problem. But when I do it in code it fails.

Example text to write and what it displays:

ÊĞ9z –4àO$&ê\±"
��9z �4�O$&�\�"

If it's not an ascii character, it displays a question mark. But as I said, if I manually copy and paste it in maskedTextBox, it displays all the characters as it should be.

Here is what I've already tried:

maskedTextBox1.Text = Encoding.UTF8.GetString(bytes);

maskedTextBox1.Text = Convert.ToBase64String(bytes);
 
The problem is with the bytes, either it is not UTF8 encoded or there has been an error in conversion earlier. UTF8 encoded byte data of that string will display correctly from Encoding.UTF8.GetString.
 
Back
Top Bottom