Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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ß ???

like image 239
insomnium_ Avatar asked Mar 29 '26 16:03

insomnium_


2 Answers

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.

like image 178
Mark Peters Avatar answered Mar 31 '26 10:03

Mark Peters


I've written a library that will decode these sorts of strings. You can find it at http://github.com/jstedfast/MimeKit

Specifically, take a look at MimeKit.Utils.Rfc2047.DecodeText()

like image 30
jstedfast Avatar answered Mar 31 '26 11:03

jstedfast