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

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 Shared Function ToBase64String ( _
	inArray As Byte() _
) As String


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 Nothing.

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.

Dim bytes() As Byte
Dim originalString As String = "The contents of the original string form a sentence."
outputBlock.Text &= String.Format("The original string: {0}   {1}", _
                    vbCrLf, originalString) & vbCrLf

' Convert the string to a byte array.
Dim encoder As New UnicodeEncoding()
bytes = encoder.GetBytes(originalString)

' Convert the byte array to a base 64 encoded string.
Dim encodedString As String = Convert.ToBase64String(bytes)
' Display the encoded string.
outputBlock.Text &= String.Format("The UUEncoded string: {0}   {1}", _
                    vbCrLf, encodedString) & vbCrLf

' 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: {0}   {1}", _
                    vbCrLf, originalString) & vbCrLf
' 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

© 2015 Microsoft