Mega Code Archive

 
Categories / C# / File Stream
 

Convert Byte array to Base64 Char Array

using System; using System.IO; class Test {     public static void Main() {         // The size of the char[] must          // be at least 4/3 the size of the source byte[] and must be          // divisible by 4.         byte[] data = { 0x01, 0x02, 0x5A, 0xFF, 0x0, 0xF0, 0x4D, 0x62, 0x78,               0xD2, 0xC5, 0xA1, 0x5A, 0xD6, 0x0C, 0xA9, 0xA6, 0x63, 0x3D, 0xC2,              0xD5, 0x0F, 0xCC, 0x01, 0xF2, 0x0C};         char[] base64data =  new char[(int)(Math.Ceiling((double)data.Length / 3) * 4)];         Console.WriteLine("\nByte array encoding/decoding");         Convert.ToBase64CharArray(data, 0, data.Length, base64data, 0);         Console.WriteLine(new String(base64data));     } }