C# byte[] to base64 code example

Example 1: convert to base64 c#

public static string Base64Encode(string plainText) {
  var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
  return System.Convert.ToBase64String(plainTextBytes);
}

Example 2: base64 string to byte array c#

byte[] l_Data = Convert.FromBase64String(l_PlainText);

Example 3: base64decode C#

string base64Encoded = "your-encoded-text";
string base64Decoded;
byte[] data = System.Convert.FromBase64String(base64Encoded);
base64Decoded = System.Text.ASCIIEncoding.ASCII.GetString(data);

Example 4: convert array byte to string 64

byte[] temp_backToBytes = Convert.FromBase64String(temp_inBase64);

Example 5: c# byte array to base64

public static string ToBase64String (byte[] inArray, int offset, int length, Base64FormattingOptions options);

Tags:

Java Example