C++ OPEN SSL 库 HMAC 功能返回值每次运行时都不相同
C++ OPEN SSL Library HMAC funtion return value is not same everytime I run?
我正在尝试使用 C++ 打开 SSL 库中的 HMAC SHA256 哈希函数,但是当我打印结果十六进制值时,我看到每次运行代码时我的输出都不同。可能是什么问题
#include <iostream>
#include <string>
#include <openssl/hmac.h>
int main(){
std::cout << "Generating key for RRC" << std::endl;
std::array <char, 32> test = {0x69, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01,
0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01,
0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01,
0x00, 0x01 };
std::array <char, 5> string = = {0x69, 0x03, 0x01, 0x02, 0x01 };
unsigned int lengthResult;
unsigned char result[EVP_MAX_MD_SIZE];
HMAC(EVP_sha256(), (unsigned char*)test.data(), test.size(),
(unsigned char*)string.data(), string.size(),
result, &lengthResult);
for (auto i:result)
std::cout << i + 0 <<" " ;
}
HMAC_SHA256末尾生成一个 SHA256 总和,即 32 个字节。EVP_MAX_MD_SIZE是 64 字节,用随机内存垃圾初始化。如果我编译并运行您的代码,前 32 个字节总是相同的。
相关文章:
- 字符串函数在目标C++上运行时C++返回空
- 使用 Google 基准测试时返回值会发生什么情况?
- 如何设计运行时分配值枚举?
- 单次运行时指针值的变化
- wifi.status(),在AP_Mode运行时返回WL_Disconnected(6)
- getPeername()在客户端在虚拟机上运行时返回我的本地主机地址
- 当 C++11 应用程序使用非 C++11 库时返回值损坏
- 函数在无法分配空间时返回值
- 访问类的成员时返回值错误
- MessageBox-当框没有“取消”按钮时返回值
- 在C++中使用临时变量时返回值优化(RVO)
- C++-Static_assert和constexpr函数在运行时求值的能力
- 构造函数中表达式的编译时或运行时求值
- 此函数如何在不应该返回值时返回值?
- setlocale() 在以 root 身份运行时返回 'C'
- 在运行时赋值后为只读的变量
- 基于运行时bool值创建模板类
- 如何在运行时将值推回融合向量
- 通过引用返回时返回值优化
- 在运行时赋值const