载UE4里面如何写一个函数可以实现 Hmac-sha1算法
时间: 2023-04-05 09:00:20
浏览: 387
可以使用OpenSSL库中的HMAC函数来实现Hmac-sha1算法。具体实现方法如下:
1. 引入OpenSSL库头文件
#include <openssl/hmac.h>
2. 定义函数
void HmacSha1(const char* key, const char* data, unsigned char* result) {
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx, key, strlen(key), EVP_sha1(), NULL);
HMAC_Update(&ctx, (unsigned char*)data, strlen(data));
unsigned int len = 0;
HMAC_Final(&ctx, result, &len);
HMAC_CTX_cleanup(&ctx);
3. 调用函数
unsigned char result[20];
HmacSha1("key", "data", result);
其中,key为密钥,data为待加密数据,result为加密结果,长度为20字节。
相关问题
Python 实现HMAC-SHA1加密算法
使用Python内置的 `hmac` 和 `hashlib` 模块可以很方便地实现HMAC-SHA1加密算法。
以下是一个示例代码:
```python
import hmac
import hashlib
def hmac_sha1(key, message):
key = bytes(key, 'utf-8')
message = bytes(message, 'utf-8')
hmac_obj = hmac.new(key, message, hashlib.sha1)
return hmac_obj.hexdigest()
```
HMAC-SHA256 算法作用
最低
0.47元/天
开通会员,查看完整答案

成为会员后, 你将解锁


相关推荐












