UTF8 encoding in base64string and saving to database

I am currently trying to encode data before storing it in my database.

try
{
    byte[] byteEncString = new byte[_strToConvert.Length];
    byteEncString = System.Text.Encoding.UTF8.GetBytes(_strToConvert);
    string strEncoded = Convert.ToBase64String(byteEncString);
    return strEncoded;
}

Does anyone know how long a string of 15 characters will exist after it is encoded through utf8 and base64string? Also, is there any max? My field on sql server is only 50, and I want to limit it to this range. Thoughts?

+3
source share
1 answer

Well, on the one hand, it makes no sense to create a byte array and then ignore it - so your code will be simpler:

byte[] byteEncString = Encoding.UTF8.GetBytes(_strToConvert);
return Convert.ToBase64String(byteEncString);

.NET char 3 , UTF-8 1 45- . base64 3 4 , 60 base64.


1 , , , . 4 , 2 , " char" 2.

+5

All Articles