ToBase64String Method (Byte[])
Collapse the table of content
Expand the table of content

Convert.ToBase64String Method (Byte[])

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft