问题描述
我有以下简单的程序:
#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;
}
当我运行它时,在命令行上输出文本:“going to calculate the digest”,程序不会继续。它挂了。 有谁知道为什么?我正在尝试遵循 Crypto++ wiki 上的示例,这与他们的非常相似。 在最终调用之后,我想对摘要进行 base64 编码,您可以删除该部分,它使用一个 boost 头文件。
谢谢, 问候
解决方法
换行
SHA3 digestAlgo = SHA3_256();
到
SHA3_256 digestAlgo;