解码 Base64/引用的可打印编码的 UTF8 字符串

发布于 2025-01-05 05:17:59 字数 728 浏览 1 评论 0原文

在我的 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:

Solution Here

Alternative solution

Update:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

美煞众生 2025-01-12 05:17:59

这似乎是 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.

苏别ゝ 2025-01-12 05:17:59

我编写了一个库来解码这些类型的字符串。您可以在 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()

漆黑的白昼 2025-01-12 05:17:59

它实际上是一个 base-64 字符串:

        string zz = "SWhyZSBCZXN0ZWxsdW5nIC0gVmVyc2FuZGJlc3TDpHRpZ3VuZyAtIDExMDU4OTEyNDY=";

        byte[] dd = Convert.FromBase64String(zz);

        // Returns Ihre Bestellung - Versandbestätigung - 1105891246
        string yy = System.Text.Encoding.UTF8.GetString(dd);

It's actually a base-64 string:

        string zz = "SWhyZSBCZXN0ZWxsdW5nIC0gVmVyc2FuZGJlc3TDpHRpZ3VuZyAtIDExMDU4OTEyNDY=";

        byte[] dd = Convert.FromBase64String(zz);

        // Returns Ihre Bestellung - Versandbestätigung - 1105891246
        string yy = System.Text.Encoding.UTF8.GetString(dd);
你列表最软的妹 2025-01-12 05:17:59

这是一个编码字,当存在非 ASCII 内容时在电子邮件标头中使用。编码字在 RFC 2047 中定义:

https://www.rfc-editor。 org/rfc/rfc2047#section-2

编码词的 BNF 是:

encoded-word = "=?" charset "?" encoding "?" encoded-text "?="

所以正确的解释方法是:

  1. 数据是第三个和第四个问号
  2. 它已经过 Base64 编码(“B”代表 Base64;如果它是
    'Q' 那么它将被引用-可打印)。
  3. 一旦你解码了
    数据,它将采用 UTF-8 字符集。

正如 @Shai 正确指出的那样,结果是:

Ihre Bestellung - Versandbestätigung - 1105891246

这是德语。变音符号显然是 UTF-8 的原因,因此需要编码的单词。翻译过来是:

Your order - Delivery confirmation - 1105891246

显然这是一个订单的追踪号码。

所有现代电子邮件客户端(和 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:

encoded-word = "=?" charset "?" encoding "?" encoded-text "?="

So the correct way to interpret this is:

  1. The data is the stuff between the 3rd and 4th question marks
  2. It has been Base64 encoded (the 'B' stands for Base64; if it were a
    'Q' then it would be quoted-printable).
  3. Once you decode the
    data, it will be in the UTF-8 character set.

The result, as @Shai correctly pointed out, is:

Ihre Bestellung - Versandbestätigung - 1105891246

This is German. The umlaut is obviously the reason for the UTF-8 and thus the need for an encoded word. The translation is:

Your order - Delivery confirmation - 1105891246

Apparently it's a tracking number for an order.

All modern email clients (and Outlook) transparently support encoded words.

安静被遗忘 2025-01-12 05:17:59

那不是UTF8。那是一个 Base64 编码的字符串。

UTF-8仅表示目标字符串是UTF8格式。
解码Base64字符串后:

SWhyZSBCZXN0ZWxsdW5nIC0gVmVyc2FuZGJlc3TDpHRpZ3VuZyAtIDExMDU4OTEyNDY=

您将得到以下结果:

Ihre Bestellung - Versandbestätigung - 1105891246

参见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:

SWhyZSBCZXN0ZWxsdW5nIC0gVmVyc2FuZGJlc3TDpHRpZ3VuZyAtIDExMDU4OTEyNDY=

You'll get the following result:

Ihre Bestellung - Versandbestätigung - 1105891246

See Base64 online decode/encode

心房的律动 2025-01-12 05:17:59

看起来像一个 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

一刻暧昧 2025-01-12 05:17:59

这有点猜测,但让我们尝试

  • 从开头删除 =? 并从结尾删除 ?=
  • 将开头保留到下一个 ? :字符集
  • 删除 B? - 不知道,它是什么
  • 通过 System.Convert.FromBase64String()< 将其余部分转换为 byte[] /code>
  • 通过以下方式将其转换为最终字符串Encoding.GetSTRing() 使用第二步中记住的字符集

This is a bit of guesswork, but let's try

  • remove =? from start and ?= from end
  • keep the start up to the next ? as the character set
  • Remove the B? - don't know, what it is
  • Convert the rest to a byte[] via System.Convert.FromBase64String()
  • Convert this to the final String via Encoding.GetSTring() using the character set remembered in the second step
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文