1 public string Base64Encode(string data)
2 {
3 byte[] encData_byte = new byte[data.Length];
4 encData_byte = System.Text.Encoding.UTF8.GetBytes(data);
5 string encodedData = Convert.ToBase64String(encData_byte);
6 return encodedData;
7 }
8
9
10 public string Base64Decode(string data)
11 {
12 System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
13 System.Text.Decoder utf8Decode = encoder.GetDecoder();
14
15 byte[] todecode_byte = Convert.FromBase64String(data);
16 int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
17 char[] decoded_char = new char[charCount];
18 utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
19 string result = new String(decoded_char);
20 return result;
21
22 }