Convert.FromBase64String(String) Method in C#


The Convert.FromBase64String(String) method in C# converts the specified string, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array.

Syntax

Following is the syntax −

public static byte[] FromBase64String (string str);

Above, the parameter str is the string to convert.

Example

Let us now see an example to implement the Convert.FromBase64String(String) 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

Updated on: 05-Nov-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements