• <bdo id='z74RY'></bdo><ul id='z74RY'></ul>

    <tfoot id='z74RY'></tfoot>
    <i id='z74RY'><tr id='z74RY'><dt id='z74RY'><q id='z74RY'><span id='z74RY'><b id='z74RY'><form id='z74RY'><ins id='z74RY'></ins><ul id='z74RY'></ul><sub id='z74RY'></sub></form><legend id='z74RY'></legend><bdo id='z74RY'><pre id='z74RY'><center id='z74RY'></center></pre></bdo></b><th id='z74RY'></th></span></q></dt></tr></i><div id='z74RY'><tfoot id='z74RY'></tfoot><dl id='z74RY'><fieldset id='z74RY'></fieldset></dl></div>

  • <small id='z74RY'></small><noframes id='z74RY'>

      1. <legend id='z74RY'><style id='z74RY'><dir id='z74RY'><q id='z74RY'></q></dir></style></legend>

        尝试解码不在 base64 字符集中的值

        时间:2023-07-18

      2. <tfoot id='MarBo'></tfoot><legend id='MarBo'><style id='MarBo'><dir id='MarBo'><q id='MarBo'></q></dir></style></legend>

            <i id='MarBo'><tr id='MarBo'><dt id='MarBo'><q id='MarBo'><span id='MarBo'><b id='MarBo'><form id='MarBo'><ins id='MarBo'></ins><ul id='MarBo'></ul><sub id='MarBo'></sub></form><legend id='MarBo'></legend><bdo id='MarBo'><pre id='MarBo'><center id='MarBo'></center></pre></bdo></b><th id='MarBo'></th></span></q></dt></tr></i><div id='MarBo'><tfoot id='MarBo'></tfoot><dl id='MarBo'><fieldset id='MarBo'></fieldset></dl></div>
            • <bdo id='MarBo'></bdo><ul id='MarBo'></ul>

              1. <small id='MarBo'></small><noframes id='MarBo'>

                    <tbody id='MarBo'></tbody>
                • 本文介绍了尝试解码不在 base64 字符集中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用以下代码片段使用 Boost C++ 库对字符串进行 base64 编码和解码.

                  I am using the following code snippet to base64 encode and decode a string using Boost C++ library.

                  //Base64 Encode Implementation using Boost C++ library
                  const std::string base64_padding[] = {"", "=", "=="};
                  
                  std::string X_Privet_Token_Generator::base64_encode(const std::string & s)
                  {
                    namespace bai = boost::archive::iterators;
                  
                    std::stringstream os;
                  
                    // convert binary values to base64 characters
                    typedef bai::base64_from_binary
                  
                    // retrieve 6 bit integers from a sequence of 8 bit bytes
                    <bai::transform_width<const char *, 6, 8> > base64_enc; // compose all the above operations in to a new iterator
                  
                    std::copy(base64_enc(s.c_str()), base64_enc(s.c_str() + s.size()), std::ostream_iterator<char>(os));
                  
                    os << base64_padding[s.size() % 3];
                    return os.str();
                  }
                  
                  std::string X_Privet_Token_Generator::base64_decode(std::string & s)
                  {
                    namespace bai = boost::archive::iterators;
                  
                    std::stringstream os;
                  
                    // convert binary values to base64 characters
                    typedef bai::binary_from_base64
                  
                    <bai::transform_width<const char *, 8, 6> > base64_dec;
                  
                    unsigned int size = s.size();
                  
                    // Remove the padding characters, cf.
                    if (size && s[size - 1] == '=')
                    {
                        --size;
                        if (size && s[size - 1] == '=')
                            --size;
                    }
                  
                    if (size == 0)
                        return std::string();
                  
                    LOGINFO("Hash decoded token : %s", s.c_str());
                    std::copy(base64_dec(s.data()), base64_dec(s.data() + size), std::ostream_iterator<char>(os));
                    std::cout<< os.str();
                    return os.str();
                  }
                  

                  编码效果很好,但是在解码时出现以下错误:

                  Encoding works well, however, while decoding I get the following error:

                  在抛出 boost::archive::iterators::dataflow_exception

                  what():尝试解码不在 base64 字符集中的值

                  what(): attempt to decode a value not in base64 char set

                  是否是导致此问题的填充字符之一?我在这里遗漏了什么吗?

                  Is it one of the padded characters that is causing this issue? Am I missing something here?

                  推荐答案

                  填充字符 '=' 是 b64 编码数据的一部分,在解码之前不应删除.b64 以 4 个字符的块进行编码,我怀疑在解码时它会在字符串末尾读取 '' 而不是预期的 '='.

                  The padding characters '=' are part of the b64 encoded data and should not be removed before decoding. b64 is encoded in blocks of 4 character, I suspect that while decoding it reads a '' instead of an expected '=' at the end of the string.

                  这篇关于尝试解码不在 base64 字符集中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:以自定义对象为键的 hash_map 的 C++ Boost.Serialization 错误 下一篇:增强使用结构中包含的 typedef 定义的本机类型的序列化

                  相关文章

                  1. <tfoot id='HlYQ0'></tfoot>

                    <small id='HlYQ0'></small><noframes id='HlYQ0'>

                  2. <legend id='HlYQ0'><style id='HlYQ0'><dir id='HlYQ0'><q id='HlYQ0'></q></dir></style></legend>
                    <i id='HlYQ0'><tr id='HlYQ0'><dt id='HlYQ0'><q id='HlYQ0'><span id='HlYQ0'><b id='HlYQ0'><form id='HlYQ0'><ins id='HlYQ0'></ins><ul id='HlYQ0'></ul><sub id='HlYQ0'></sub></form><legend id='HlYQ0'></legend><bdo id='HlYQ0'><pre id='HlYQ0'><center id='HlYQ0'></center></pre></bdo></b><th id='HlYQ0'></th></span></q></dt></tr></i><div id='HlYQ0'><tfoot id='HlYQ0'></tfoot><dl id='HlYQ0'><fieldset id='HlYQ0'></fieldset></dl></div>

                      <bdo id='HlYQ0'></bdo><ul id='HlYQ0'></ul>