namespace EncodeandDecode
{
class Program
{
static void Main(string[] args)
{
byte[] bytes = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
Console.WriteLine("The byte array: ");
Console.WriteLine(" {0}\n", BitConverter.ToString(bytes));
// BitConverter.ToString(bytes)是转换为16进制字符串
string s = Convert.ToBase64String(bytes);
//s = bytes转换成的16进制字符串再进行Base64加密而生成的字符串
Console.WriteLine("The base 64 string: ");
Console.WriteLine(" {0}\n", s);
byte[] newBytes = Convert.FromBase64String(s);
//把s还原回16进制字符串
Console.WriteLine("The restored byte array: ");
Console.WriteLine(" {0}\n", BitConverter.ToString(newBytes));
}
}
}