Convert.ToBase64CharArray() and Convert.FromBase64CharArray
using System;
class Sample
{
public static void Main()
{
byte[] byteArray1 = new byte[256];
byte[] byteArray2 = new byte[256];
char[] charArray = new char[352];
int charArrayLength;
for (int x = 0; x < byteArray1.Length; x++)
{
byteArray1[x] = (byte)x;
Console.Write("{0:X2} ", byteArray1[x]);
}
charArrayLength = Convert.ToBase64CharArray(byteArray1, 0, byteArray1.Length,
charArray, 0, Base64FormattingOptions.InsertLineBreaks);
Console.Write(charArrayLength);
Console.WriteLine(new String(charArray));
byteArray2 = Convert.FromBase64CharArray(charArray, 0, charArrayLength);
Console.WriteLine(ArraysAreEqual(byteArray1, byteArray2));
}
public static bool ArraysAreEqual(byte[] a1, byte[] a2)
{
if (a1.Length != a2.Length) return false;
for (int i = 0; i < a1.Length; i++)
if (a1[i] != a2[i]) return false;
return true;
}
}
Related examples in the same category