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.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- inArray
- Type:
System.Byte
()
An array of 8-bit unsigned integers.
| Exception | Condition |
|---|---|
| ArgumentNullException | 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: ' VABoAGUAIABjAG8AbgB0AGUAbgB0AHMAIABvAGYAIAB0AGgAZQAgAG8AcgBpAGcAaQBuAGEAbAAgA ' HMAdAByAGkAbgBnACAAZgBvAHIAbQAgAGEAIABzAGUAbgB0AGUAbgBjAGUALgA= ' The original string restored: ' The contents of the original string form a sentence.