Convert.ToBase64String Method (Byte[])

Converts an array of 8-bit unsigned integers to its equivalent String representation encoded with base 64 digits.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static string ToBase64String(
	byte[] inArray


Type: System.Byte[]
An array of 8-bit unsigned integers.

Return Value

Type: System.String
The String representation, in base 64, of the contents of inArray.


inArray is null.

The elements of inArray are taken as a numeric value and converted to a String representation encoded with base 64 digits.

The base 64 digits in ascending order from zero are the uppercase characters 'A' to 'Z', the lowercase characters 'a' to 'z', the numerals '0' to '9', and the symbols '+' and '/'. The valueless character, '=', is used for trailing padding.

The following example uses the ToBase64String(Byte[]) method to convert an array of UTF16-encoded bytes to a UUEncoded string. It then uses the FromBase64String method to convert the UUEncoded string back to the original string.

byte[] bytes;
string originalString = "The contents of the original string form a sentence.";
outputBlock.Text += String.Format("The original string:\n   {0}\n", 

// Convert the string to a byte array.
UnicodeEncoding encoder = new UnicodeEncoding();
bytes = encoder.GetBytes(originalString);

// Convert the byte array to a base 64 encoded string.
string encodedString = Convert.ToBase64String(bytes);
// Display the encoded string.
outputBlock.Text += String.Format("The UUEncoded string:\n   {0}\n", 

// Convert UUEncoded string to a byte array.
bytes = Convert.FromBase64String(encodedString);

// Convert byte array back to the original string.
originalString = encoder.GetString(bytes, 0, bytes.Length); 
outputBlock.Text += String.Format("The original string restored:\n   {0}\n", 
// The example displays the following output:
//       The original string:
//          The contents of the original string form a sentence.
//       The UUEncoded string:
//       The original string restored:
//          The contents of the original string form a sentence.


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions