首页 > 解决方案 > Crypto++:哈希生成在 Windows 10 上挂起

问题描述

我有以下简单的程序:

#include <cryptlib.h>
#include "sha.h"
#include <sha3.h>
#include <filters.h>
#include <hex.h>
#include <beast/core/detail/base64.hpp>

using namespace CryptoPP;
using namespace boost::beast::detail::base64;

int main(int argc, char** argv) {

    if (argc < 2) {
        std::cout << "missing argument 1 : password";
        return 0;
    }
    std::string password = std::string(argv[1]);
    byte digest[SHA3_256::DIGESTSIZE];

    SHA3 digestAlgo = SHA3_256();
    std::cout << "going to calculate the digest\n";
    digestAlgo.Update((const byte*) password.data(), password.size());
    std::cout << "updated...\n";
    digestAlgo.Final(digest);
    std::cout << "calculated the digest\n";

    char* b64encodedHash = (char*)malloc(sizeof(byte)*1000);
    encode(b64encodedHash, digest, sizeof(byte)*1000);

    std::cout << "password hashed : " << b64encodedHash << "\n";

    return 1;
}

当我运行它时,在命令行上输出文本:“要计算摘要”并且程序不会继续。它挂起。有谁知道为什么?我正在尝试遵循 Crypto++ wiki 上的示例,这与他们的非常相似。在 Final call 我想对摘要进行 base64 编码之后,您可以删除该部分,它使用 boost 头文件。

感谢和问候

标签: c++crypto++sha-3

解决方案


换行

SHA3 digestAlgo = SHA3_256();

SHA3_256 digestAlgo;

推荐阅读