Search code examples
c#utf-8base64mimeemail-headers

Decoding Base64 / Quoted Printable encoded UTF8 string


In my ASP.Net application working process, I need to do some work with string, which equals something like

=?utf-8?B?SWhyZSBCZXN0ZWxsdW5nIC0gVmVyc2FuZGJlc3TDpHRpZ3VuZyAtIDExMDU4OTEyNDY=?=

How can I decode it to normal human language?

Thanks in advance!

Update:

Convert.FromBase64String() does not work for string, which equals =?UTF-8?Q?Bestellbest=C3=A4tigung?=

I get The format of s is invalid. s contains a non-base-64 character, more than two padding characters, or a non-white space-character among the padding characters. exception.

Update:

Solution Here

Alternative solution

Update:

What kind of string encoding is that: Nweiß ???


Solution

  • This seems to be MIME Header Encoding. The Q in your second example indicates that it is Quoted Printable.

    This question seems to cover the variants fairly well. In a quick search I didn't find any .NET libraries to decode this automatically, but it shouldn't be hard to do manually if you need to.