Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.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
C++ 相同输入的boost sha1和openssl库的不同输出_C++_Boost_Openssl - Fatal编程技术网

C++ 相同输入的boost sha1和openssl库的不同输出

C++ 相同输入的boost sha1和openssl库的不同输出,c++,boost,openssl,C++,Boost,Openssl,我试图了解更多关于boost和sha1的信息。我已经编写了以下代码来测试输出。除了boost之外,我还安装了openssl库。 我已经写了下面的代码,我在openssl和BoostSHA1中得到了相同值的不同值。 输入字符串:“te99999” std::字符串makeSHA1boostV1(常量字符文本[]) { boost::uuids::detail::sha1-sha1; 无符号整数散列[5]; sha1.进程字节(text,sizeof(text)-1); sha1.获取_摘要(散

我试图了解更多关于boost和sha1的信息。我已经编写了以下代码来测试输出。除了boost之外,我还安装了openssl库。
我已经写了下面的代码,我在openssl和BoostSHA1中得到了相同值的不同值。
输入字符串:“te99999”

std::字符串makeSHA1boostV1(常量字符文本[])
{
boost::uuids::detail::sha1-sha1;
无符号整数散列[5];
sha1.进程字节(text,sizeof(text)-1);
sha1.获取_摘要(散列);
std::ostringstream buf;

这不是boost的问题,而是您使用流的问题


使用
打印数字这不是boost的问题,而是使用流的问题


设置std::setfill('0')后,打印带有
的数字未获得预期输出。@RAW您以何种方式未获得预期输出?您是否也设置了
std::setw
?buf仍然未获得前导zeros@RAW
std::setw(sizeof(hash[i])/2)
应该是
std::setw(sizeof(hash[i])*2)
。我在几个小时前修复了答案中的错误。(
*2
,因为每个字节需要两个字符以十六进制表示)。设置std::setfill('0')后未获得预期输出@RAW您以什么方式没有获得预期的输出?您是否也设置了
std::setw
?buf仍然没有获得前导zeros@RAW
std::setw(sizeof(hash[i])/2)
应该是
std::setw(sizeof(hash[i])*2)
。几个小时前我在回答中纠正了这个错误。(
*2
,因为每个字节需要两个字符以十六进制表示)。
std::string makeSHA1boostV1(const char text[])
    {
        boost::uuids::detail::sha1 sha1;
        unsigned int hash[5];
        sha1.process_bytes(text, sizeof(text)-1);
        sha1.get_digest(hash);
         std::ostringstream buf;
        std::cout << "Hash: ";
        for(std::size_t i=0; i<sizeof(hash)/sizeof(hash[0]); ++i) {
            std::cout <<"sha hash "<<hash[i]<<std::endl;
            std::cout << std::hex <<hash[i];
            buf << std::hex <<hash[i];
        }
        std::cout << std::endl;
        std::cout << "sha1  "<<buf.str()<<std::endl;
        return buf.str();
    }
buf << std::hex << std::setfill('0') << std::setw(sizeof(hash[i])*2) << hash[i];