4dots Software CODE BLOG

How to Base64 Decode a String with custom encoding

To Base64 decode a string with custom encoding do the following :

	string text_to_decode="aGVsbG8gd29ybGQgIQ==";
	Encoding enc = Encoding.Default;            
	string decoded_base64str = enc.GetString(System.Convert.FromBase64String(text_to_decode));

You can change the enc Encoding with the encoding you want.

You can get an encoding from its codepage number with enc=Encoding.GetEncoding(codepage_number); e.g.

Encoding enc=Encoding.GetEncoding(65001);
for Unicode UTF-8 encoding.

Download Demo Project

Encode Decode Demo Project

Please Donate!

Please Share!