In this post, we’ll discuss Base64 Encoding and Decoding in C#.

Base64 is a group of similar binary-to-text encoding schemes representing binary data in an ASCII string format by translating it into a radix-64 representation. Each Base64 digit represents exactly 6-bits of data that means 4 6-bit Base64 digits can represent 3 bytes.

 
Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remain intact without modification during transport. Base64 is commonly used in a number of applications, including email via MIME and storing complex data in XML.

C# provides support for Base64 Encoding and Decoding capabilities in System.Convert utility class, which consists of static methods for obtaining instances of encoders (Base64.Encoder) and decoders (Base64.Decoder) for the Base64 encoding scheme.

 
The following program uses the Convert.ToBase64String() method for encoding the specified byte array into a Base64 encoded string and Convert.FromBase64String() method for decoding back the Base64 encoded string into a newly allocated byte array.

Download  Run Code

That’s all about base64 encoding and decoding in C#.

 
Also See:

Base64 Encoding and Decoding in Java

Base64 Encoding and Decoding in JavaScript