The Convert.ToBase64String() method in C# is used to convert the value of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with base-64 digits.
Syntax
Following is the syntax −
public static string ToBase64String (byte[] arr);
Above, arr is an array of 8-bit unsigned integers.
Example
Let us now see an example to implement the Convert.ToBase64String() method −
Using System;
public class Demo {
public static void Main(){
byte[] val1 = {5,10,15,20,25,30};
string str = Convert.ToBase64String(val1);
Console.WriteLine("Base 64 string: '{0}'", str);
byte[] val2 = Convert.FromBase64String(str);
Console.WriteLine("Converted byte value: {0}", BitConverter.ToString(val2));
}
}Output
This will produce the following output −
Base 64 string: 'BQoPFBke' Converted byte value: 05-0A-0F-14-19-1E