风还在微微厮杀 2020-03-09 12:09 采纳率: 0%
浏览 3144

C++ 使用Openssl进行HMAC- sha256加密

bool calc_HMAC_SHA256(const std::string &key, const std::string &input, std::string *hmac)
{
unsigned char md[32] = { 0 };//32 bytes

char format_md[65] = { 0 };
unsigned int md_len = sizeof(md);
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
if (!HMAC_Init_ex(&ctx, key.data(), (int)key.length(), EVP_sha256(), NULL) ||
!HMAC_Update(&ctx, (const unsigned char *)input.data(), input.length()) ||
!HMAC_Final(&ctx, md, &md_len)) {
HMAC_CTX_cleanup(&ctx);
return false;
}
HMAC_CTX_cleanup(&ctx);
for (int i = 0; i < 32; i++) {
snprintf(&format_md[i * 2], 3, "%02x", md[i]); //二进制转为十六进制大写

}
hmac->assign(format_md);
// 转大写

transform(hmac->begin(), hmac->end(), hmac->begin(), ::toupper);
return true;
}
openssl已经导入,lib也引用了,运行时
CloudPayInfo.obj : error LNK2001: 无法解析的外部符号 _EVP_sha256
1>CloudPayInfo.obj : error LNK2001: 无法解析的外部符号 _HMAC_CTX_init
1>CloudPayInfo.obj : error LNK2001: 无法解析的外部符号 _HMAC_CTX_cleanup
1>CloudPayInfo.obj : error LNK2001: 无法解析的外部符号 _HMAC_Init_ex
1>CloudPayInfo.obj : error LNK2001: 无法解析的外部符号 _HMAC_Update
1>CloudPayInfo.obj : error LNK2001: 无法解析的外部符号 _HMAC_Final
请问大佬们怎么解决啊?

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2020-03-09 22:36
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题