Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Base64解码错误 使用Boost C++库,我尝试使用以下代码:BASE64编码以下的BASE64编码值:OTE4ZDYXZ0MZZYMYZMEDZVMY2NJNYMYYOTU5MTMT0NZVMYWWMJOX: std::string base64_decode(const std::string& s) { namespace bai = boost::archive::iterators; std::stringstream os; typedef bai::transform_width<bai::binary_from_base64<const char *>, 8, 6> base64_dec; unsigned int size = s.size(); // Remove the padding characters, cf. https://svn.boost.org/trac/boost/ticket/5629 if (size && s[size - 1] == '=') { --size; if (size && s[size - 1] == '=') --size; } if (size == 0) return std::string(); std::copy(base64_dec(s.data()), base64_dec(s.data() + size), std::ostream_iterator<char>(os)); return os.str(); std::string base64_解码(const std::string&s){ 名称空间bai=boost::archive::迭代器; std::stringstream操作系统; typedef bai::变换宽度基64度; 无符号整数大小=s.size(); //删除填充字符,cf。https://svn.boost.org/trac/boost/ticket/5629 如果(大小和大小[size-1]='='='){ --大小; if(size&&s[size-1]='='=')--size; } if(size==0)返回std::string(); 标准::复制(base64_dec(s.data()),base64_dec(s.data()+大小), std::ostream_迭代器(os)); 返回os.str();_C++_C++11_Boost_Character Encoding_Base64 - Fatal编程技术网

Base64解码错误 使用Boost C++库,我尝试使用以下代码:BASE64编码以下的BASE64编码值:OTE4ZDYXZ0MZZYMYZMEDZVMY2NJNYMYYOTU5MTMT0NZVMYWWMJOX: std::string base64_decode(const std::string& s) { namespace bai = boost::archive::iterators; std::stringstream os; typedef bai::transform_width<bai::binary_from_base64<const char *>, 8, 6> base64_dec; unsigned int size = s.size(); // Remove the padding characters, cf. https://svn.boost.org/trac/boost/ticket/5629 if (size && s[size - 1] == '=') { --size; if (size && s[size - 1] == '=') --size; } if (size == 0) return std::string(); std::copy(base64_dec(s.data()), base64_dec(s.data() + size), std::ostream_iterator<char>(os)); return os.str(); std::string base64_解码(const std::string&s){ 名称空间bai=boost::archive::迭代器; std::stringstream操作系统; typedef bai::变换宽度基64度; 无符号整数大小=s.size(); //删除填充字符,cf。https://svn.boost.org/trac/boost/ticket/5629 如果(大小和大小[size-1]='='='){ --大小; if(size&&s[size-1]='='=')--size; } if(size==0)返回std::string(); 标准::复制(base64_dec(s.data()),base64_dec(s.data()+大小), std::ostream_迭代器(os)); 返回os.str();

Base64解码错误 使用Boost C++库,我尝试使用以下代码:BASE64编码以下的BASE64编码值:OTE4ZDYXZ0MZZYMYZMEDZVMY2NJNYMYYOTU5MTMT0NZVMYWWMJOX: std::string base64_decode(const std::string& s) { namespace bai = boost::archive::iterators; std::stringstream os; typedef bai::transform_width<bai::binary_from_base64<const char *>, 8, 6> base64_dec; unsigned int size = s.size(); // Remove the padding characters, cf. https://svn.boost.org/trac/boost/ticket/5629 if (size && s[size - 1] == '=') { --size; if (size && s[size - 1] == '=') --size; } if (size == 0) return std::string(); std::copy(base64_dec(s.data()), base64_dec(s.data() + size), std::ostream_iterator<char>(os)); return os.str(); std::string base64_解码(const std::string&s){ 名称空间bai=boost::archive::迭代器; std::stringstream操作系统; typedef bai::变换宽度基64度; 无符号整数大小=s.size(); //删除填充字符,cf。https://svn.boost.org/trac/boost/ticket/5629 如果(大小和大小[size-1]='='='){ --大小; if(size&&s[size-1]='='=')--size; } if(size==0)返回std::string(); 标准::复制(base64_dec(s.data()),base64_dec(s.data()+大小), std::ostream_迭代器(os)); 返回os.str();,c++,c++11,boost,character-encoding,base64,C++,C++11,Boost,Character Encoding,Base64,看起来编码是正确的,但是,在解码时,我仍然得到以下错误:在抛出boost::archive::iterators::dataflow_exception what()的实例后调用terminate:尝试解码一个不在第行的base64字符集中的值: std::copy(base64_dec(s.data()), base64_dec(s.data() + size), std::ostream_iterator<char>(os)); std::copy(base64_dec(s.

看起来编码是正确的,但是,在解码时,我仍然得到以下错误:在抛出boost::archive::iterators::dataflow_exception what()的实例后调用terminate:尝试解码一个不在第行的base64字符集中的值:

std::copy(base64_dec(s.data()), base64_dec(s.data() + size), std::ostream_iterator<char>(os)); 
std::copy(base64_dec(s.data())、base64_dec(s.data()+size)、std::ostream_迭代器(os));

我没有评论的名声,因此这是一个答案:

“尝试解码不在base64字符集中的值”听起来像是您应该为给定的输入验证函数的实际输入

Ote4ZduxyzM0Ztiynmezzdvmy2njnjaymzyyotu5Mtg0nzvmywmjox
您的代码有效:

更改

std::copy(base64_dec(s.data()), base64_dec(s.data() + size), std::ostream_iterator<char>(os))

解决了问题。

这不是您要求的,但编码文本是用小写十六进制编码的“8:1”的sha1摘要,然后用base64编码。(不要告诉我这是密码)
return std::string( base64_dec(s.c_str()), base64_dec(s.c_str() + size))