阿里云物联网平台,三要素生成hmacmd5,hmacsha1和hmacsha256,password算法+hashmd5,hashsha1,hashsha256算法

程序在ubuntu上测试通过

测试函数:

#include "infra_md5.h"
#include "infra_sha1.h"
#include "infra_sha256.h"

#include <stdio.h>
#include <string.h>

void aliyun_generate_sign_str(const char *client_id, const char *product_key, const char *device_name, const char *device_secret)
{
    char msg[128] = {0};
    char md5[32 + 1] = {0};
    char sha1[40 + 1] = {0};
    char sha256[64 + 1] = {0};
    char md5_password[32 + 1] = {0};
    char sha1_password[40 + 1] = {0};
    char sha256_password[64 + 1] = {0};

    strcat(msg, "clientId");
    strcat(msg, client_id);
    strcat(msg, "deviceName");
    strcat(msg, device_name);
    strcat(msg, "productKey");
    strcat(msg, product_key);

    utils_md5(msg, strlen(msg), md5);
    utils_sha1(msg, strlen(msg), sha1);
    utils_sha256(msg, strlen(msg), sha256);
    
    utils_hmac_md5(msg, strlen(msg), md5_password, device_secret, strlen(device_secret));
    utils_hmac_sha1(msg, strlen(msg), sha1_password, device_secret, strlen(device_secret));
    utils_hmac_sha256(msg, strlen(msg), device_secret, strlen(device_secret), sha256_password);

    printf("md5 %s\n", md5);
    printf("sha1 %s\n", sha1);
    printf("sha256 %s\n\n", sha256);
    
    printf("md5 password = %s\n", md5_password);
    printf("sha1 password = %s\n", sha1_password);
    printf("sha256 password = %s\n", sha256_password);
}
int main(void)
{
    char* client_id = "12345";
    char* product_key = "a1H5CPxGtRU";
    char* device_name = "dev999";
    char* device_secret = "49d4b235306f3adb7c5922f00f82695b";
    
    aliyun_generate_sign_str(client_id, product_key, device_name, device_secret);
}

在线计算:

https://1024tools.com/hmac
https://1024tools.com/hash
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

测试结果:

ning@ning-virtual-machine:~/aliyun$ gcc -m32 app.c infra_md5.c infra_sha1.c infra_sha256.c
ning@ning-virtual-machine:~/aliyun$ ./a.out
md5 c2bc191cd242b4f5b7975dd6b818a864
sha1 bb02f94f65deb8460cd6f6b07760230133a7c4aa
sha256 ebf6b91a11e8a989905d8bea148734b229fafdc06a907115a0699ca49b4b151c

md5 password = d122ec51b101094237896cf275f0aa1b
sha1 password = d6ffb977aa9c1f7ecc7c4709a14b6817dc2f683e
sha256 password = 2de53bffb1f904d5963e5bec2c2381ec46bf856dc49079fe4eb78508be2f5a6e

代码下载:

csdn:点我下载

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值