解码 Base64/引用的可打印编码的 UTF8 字符串
在我的 ASP.Net 应用程序工作过程中,我需要对字符串进行一些处理,这相当于
=?utf-8?B?SWhyZSBCZXN0ZWxsdW5nIC0gVmVyc2FuZGJlc3TDpHRpZ3VuZyAtIDExMDU4OTEyNDY=?=
如何将它解码为正常的人类语言?
提前致谢!
更新:
Convert.FromBase64String()
不适用于字符串,它等于 =?UTF-8?Q?Bestellbest=C3=A4tigung?=
我得到 The format of s is invalid. s 包含非 Base-64 字符、超过两个填充字符或填充字符中包含非空格字符。
异常。
更新:
更新:
是什么样的字符串编码: Nweiß
???
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:
Update:
What kind of string encoding is that: Nweiß
???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这似乎是 MIME 标头编码。第二个示例中的 Q 表示它是 Quoted Printable。
这个问题似乎很好地涵盖了这些变体。在快速搜索中,我没有找到任何 .NET 库来自动解码此内容,但如果需要,手动执行应该不难。
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.
我编写了一个库来解码这些类型的字符串。您可以在 http://github.com/jstedfast/MimeKit 找到它
,具体请查看 <代码>MimeKit.Utils.Rfc2047.DecodeText()
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()
它实际上是一个 base-64 字符串:
It's actually a base-64 string:
这是一个编码字,当存在非 ASCII 内容时在电子邮件标头中使用。编码字在 RFC 2047 中定义:
https://www.rfc-editor。 org/rfc/rfc2047#section-2
编码词的 BNF 是:
所以正确的解释方法是:
'Q' 那么它将被引用-可打印)。
数据,它将采用 UTF-8 字符集。
正如 @Shai 正确指出的那样,结果是:
这是德语。变音符号显然是 UTF-8 的原因,因此需要编码的单词。翻译过来是:
显然这是一个订单的追踪号码。
所有现代电子邮件客户端(和 Outlook)都透明地支持编码单词。
This is an encoded word, which is used in email headers when there is non-ASCII content. Encoded words are defined in RFC 2047:
https://www.rfc-editor.org/rfc/rfc2047#section-2
The BNF for an encoded word is:
So the correct way to interpret this is:
'Q' then it would be quoted-printable).
data, it will be in the UTF-8 character set.
The result, as @Shai correctly pointed out, is:
This is German. The umlaut is obviously the reason for the UTF-8 and thus the need for an encoded word. The translation is:
Apparently it's a tracking number for an order.
All modern email clients (and Outlook) transparently support encoded words.
那不是UTF8。那是一个 Base64 编码的字符串。
UTF-8仅表示目标字符串是UTF8格式。
解码Base64字符串后:
您将得到以下结果:
参见Base64在线解码/编码
That's not UTF8. Thats a Base64 encoded string.
the UTF-8 only indicates that the target string is in UTF8 format.
After decoding the Base64 string:
You'll get the following result:
See Base64 online decode/encode
看起来像一个 base64 字符串。
尝试 Convert.FromBase64String
http://msdn.microsoft.com/en -us/library/system.convert.frombase64string.aspx
Looks like a base64 string.
Try Convert.FromBase64String
http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx
这有点猜测,但让我们尝试
=?
并从结尾删除?=
,?
:字符集B?
- 不知道,它是什么System.Convert.FromBase64String()< 将其余部分转换为
byte[]
/code>Encoding.GetSTRing()
使用第二步中记住的字符集This is a bit of guesswork, but let's try
=?
from start and?=
from end?
as the character setB?
- don't know, what it isbyte[]
viaSystem.Convert.FromBase64String()
Encoding.GetSTring()
using the character set remembered in the second step