Convert::ToBase64String Method (array<Byte>^)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

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

static String^ ToBase64String(
	array<unsigned char>^ inArray


Type: array<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.

Exception Condition

inArray is null.

The elements of inArray are taken as a numeric value and converted to a string representation that is 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 ToBase64String method is designed to process a single byte array that contains all the data to be encoded. To encode data from a stream, use the System.Security.Cryptography::ToBase64Transform class.

Ordinarily, the ToBase64String method is not used to round-trip a UUEncoded (base-64 encoded) string. That is, if you decode a string by calling the FromBase64String method, then encode the returned byte array by calling the ToBase64String method, the resulting string will not necessarily be identical to the original string. The string will round-trip only if the original string is a valid base-64 encoded string.

The following example uses the ToBase64String(array<Byte>^) method to convert a byte array to a UUencoded (base-64) string, and then calls the FromBase64String(String^) method to restore the original byte array.

No code example is currently available or this language may not be supported.

The following is a more complex example that creates a 20-element array of 32-bit integers. It then uses the BitConverter::GetBytes(Int32) method to convert each element into a byte array, which it stores in the appropriate position in a buffer by calling the Array::Copy(Array^, Int32, Array^, Int32, Int32) method. This buffer is then passed to the ToBase64String(array<Byte>^) method to create a UUencoded (base-64) string. It then calls the FromBase64String(String^) method to decode the UUencoded string, and calls the BitConverter::ToInt32 method to convert each set of four bytes (the size of a 32-bit integer) to an integer. The output from the example shows that the original array has been successfully restored.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top