Convert::FromBase64String Method (String^)


Converts the specified string, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array.

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

static array<unsigned char>^ FromBase64String(
	String^ s


Type: System::String^

The string to convert.

Return Value

Type: array<System::Byte>^

An array of 8-bit unsigned integers that is equivalent to s.

Exception Condition

s is null.


The length of s, ignoring white-space characters, is not zero or a multiple of 4.


The format of s is invalid. s contains a non-base-64 character, more than two padding characters, or a non-white space-character among the padding characters.

s is composed of base-64 digits, white-space characters, and trailing padding characters. The base-64 digits in ascending order from zero are the uppercase characters "A" to "Z", lowercase characters "a" to "z", numerals "0" to "9", and the symbols "+" and "/".

The white-space characters, and their Unicode names and hexadecimal code points, are tab (CHARACTER TABULATION, U+0009), newline (LINE FEED, U+000A), carriage return (CARRIAGE RETURN, U+000D), and blank (SPACE, U+0020). An arbitrary number of white-space characters can appear in s because all white-space characters are ignored.

The valueless character, "=", is used for trailing padding. The end of s can consist of zero, one, or two padding characters.


The FromBase64Stringmethod is designed to process a single string that contains all the data to be decoded. To decode base-64 character data from a stream, use the System.Security.Cryptography::FromBase64Transform class.

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