gpt4 book ai didi

c - 如何处理解码 Base64 字符串时出现的错误

转载 作者:行者123 更新时间:2023-11-30 16:42:57 25 4
gpt4 key购买 nike

我正在尝试编写一个小型 Base64 编码器/解码器程序,并且我正在尝试弄清楚当遇到无效字符时是否有任何规则、任何准则或预期行为。

我可能会快速失败(提示并退出),忽略无效字符(就像我对换行符所做的那样),或者采用垃圾输入、垃圾输出方法(其中数据将被部分解码,其余的取决于错误的严重性或确切数量)。

类似的一点:我想我应该忽略换行符(就像在 PEM 文件中,其中行以 64 个字符的长度断开),但是是否还有其他我可以预期的控制字符,并且应该正确忽略?

如果有任何兴趣,我正在使用纯(普通)C 进行编码,但它还没有相应的库。但这个细节对于我正在寻找的答案来说并不重要。

谢谢。

最佳答案

我很抱歉。 MIME 上的 RFC( 134115212045 )包含以下段落,我直到现在才找到:

The output stream (encoded bytes) must be represented in lines of no more than 76 characters each. All line breaks or other characters not found in Table 1 must be ignored by decoding software. In base64 data, characters other than those in Table 1, line breaks, and other white space probably indicate a transmission error, about which a warning message or even a message rejection might be appropriate under some circumstances.

无论如何,这个问题和答案在 StackOverflow 上发布是适当的。

附注如果有其他 Base64 标准和其他准则,则其他答案中的链接和引用是适当的。

关于c - 如何处理解码 Base64 字符串时出现的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45626850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com