How to encode and decode a base64 string in C#.

Use the 2 helpers methods below for encoding and decoding a base64 string.

public static string Base64Encode(string text)
     var textBytes = System.Text.Encoding.UTF8.GetBytes(text);
     return System.Convert.ToBase64String(textBytes);

public static string Base64Decode(string base64)
      var base64Bytes = System.Convert.FromBase64String(base64);
      return System.Text.Encoding.UTF8.GetString(base64Bytes);

Jack Poorte
Jack Poorte
Last updated on Sep 30, 2023

Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.