Page 1 of 1
【已解决】使用aes_inf.h头文件里的aes128_ecb_decode_raw解密接口解密错误
Posted: 2024年 Mar 6日 08:39
by 15158693303
模组:WBR1D,tuyaos:3.3.4
使用aes_inf.h头文件里的aes128_ecb_decode_raw解密接口解密错误,解密出来的数据不对,麻烦帮忙看下同样的数据,加密成功了,用同一个Key就解密不出来,以下为代码片段
Code: Select all
BYTE_T data1[] ="b4046667e3c549673aa75369b605f342";
BYTE_T datakey1[] ="6r4mq0ptoan2wf70";
//UINT32_T outlen1 = 0;
BYTE_T outdata1[33] = {0};
aes128_ecb_decode_raw(data1, strlen(data1), outdata1, datakey1);
TAL_PR_INFO("data1;%s", data1);
TAL_PR_INFO("strlen(data1);%d", strlen(data1));
TAL_PR_INFO("outdata1;%s", outdata1);
TAL_PR_INFO("strlen(outdata1);%d", strlen(outdata1));
TAL_PR_INFO("datakey1;%s", datakey1);
TAL_PR_DEBUG("AES_DE2: ");
memset(dataget,0,32);
for (int j = 0; j < strlen(outdata1); j++) {
memset(cat,0,8);
sprintf(cat,"%02x",outdata1[j]);
strcat(dataget,cat);
}
TAL_PR_INFO("dedataget;%s", dataget);
aes_free_data(outdata1);
以下为日志内容
Code: Select all
[2024-03-06 08:27:34.144]# RECV ASCII>
I][tuya_app_main.c:268] data1;b4046667e3c549673aa75369b605f342
[01-01 08:00:03 TUYA I][tuya_app_main.c:269] strlen(data1);32
[01-01 08:00:03 TUYA I][tuya_app_main.c:270] outdata1;?
[01-01 08:00:03 TUYA I][tuya_app_main.c:271] strlen(outdata1);2
[01-01 08:00:03 TUYA I][tuya_app_main.c:272] datakey1;6r4mq0ptoan2wf70
[01-01 08:00:03 TUYA D][tuya_app_main.c:273] AES_DE2:
[01-01 08:00:03 TUYA I][tuya_app_main.c:280] dedataget;9231
Re: 使用aes_inf.h头文件里的aes128_ecb_decode_raw解密接口解密错误
Posted: 2024年 Mar 6日 09:19
by 一线长天
代码里没有看到加密相关片段,请提供完整加解密代码片段与日志
Re: 使用aes_inf.h头文件里的aes128_ecb_decode_raw解密接口解密错误
Posted: 2024年 Mar 6日 09:23
by 15158693303
你好,以下为加密解密完整版片段
Code: Select all
BYTE_T data[] ="l8hpkkjnn93mx0pe";
BYTE_T datakey[] ="6r4mq0ptoan2wf70";
UINT32_T outlen = 0;
BYTE_T outdata[32] = {0};
//aes128_ecb_encode(data, strlen(data), &outdata, &outlen, datakey);
aes128_ecb_encode_raw(data, strlen(data), outdata, datakey);
TAL_PR_DEBUG("AES_EN1: ");
BYTE_T dataget[32] = {0};
CHAR_T cat[8] = {0};
/*
for (int i = 0; i < outlen; i++) {
memset(cat,0,8);
sprintf(cat,"%02x",outdata[i]);
strcat(dataget,cat);
}
*/
TAL_PR_DEBUG("outdata: %d",strlen(outdata));
for (int i = 0; i < strlen(outdata); i++) {
memset(cat,0,8);
sprintf(cat,"%02x",outdata[i]);
strcat(dataget,cat);
}
TAL_PR_INFO("%s", dataget);
aes_free_data(outdata);
//BYTE_T data1[] ="4F8949931FE40966FFDAD8230C5157B1";
BYTE_T data1[] ="b4046667e3c549673aa75369b605f342";
BYTE_T datakey1[] ="6r4mq0ptoan2wf70";
UINT32_T outlen1 = 0;
BYTE_T outdata1[33] = {0};
BYTE_T dedataget[33] = {0};
aes128_ecb_decode_raw(data1, strlen(data1), outdata1, datakey1);
TAL_PR_INFO("data1;%s", data1);
TAL_PR_INFO("strlen(data1);%d", strlen(data1));
TAL_PR_INFO("outdata1;%s", outdata1);
TAL_PR_INFO("strlen(outdata1);%d", strlen(outdata1));
TAL_PR_INFO("datakey1;%s", datakey1);
TAL_PR_DEBUG("AES_DE2: ");
memset(dedataget,0,33);
for (int j = 0; j < strlen(outdata1); j++) {
memset(cat,0,8);
sprintf(cat,"%02x",outdata1[j]);
strcat(dedataget,cat);
}
TAL_PR_INFO("dedataget;%s", dedataget);
aes_free_data(outdata1);
以下为日志
Code: Select all
[01-01 08:00:03 TUYA D][tuya_app_main.c:238] AES_EN1:
[01-01 08:00:03 TUYA D][tuya_app_main.c:249] outdata: 1
[2024-03-06 08:48:16.548]# RECV ASCII>
6
[01-01 08:00:03 TUYA I][tuya_app_main.c:256] b4046667e3c549673aa75369b605f342
[01-01 08:00:03 TUYA I][tuya_app_main.c:269] data1;b4046667e3c549673aa75369b605f342
[01-01 08:00:03 TUYA I][tuya_app_main.c:270] strlen(data1);32
[01-01 08:00:03 TUYA I][tuya_app_main.c:271] outdata1;?
[01-01 08:00:03 TUYA I][tuya_app_main.c:272] strlen(outdata1);2
[01-01 08:00:03 TUYA I][tuya_app_main.c:273] datakey1;6r4mq0ptoan2wf70
[01-01 08:00:03 TUYA D][tuya_app_main.c:274] AES_DE2:
[01-01 08:00:03 TUYA I]
[2024-03-06 08:48:16.595]# RECV ASCII>
[tuya_app_main.c:281] dedataget;9231
Re: 使用aes_inf.h头文件里的aes128_ecb_decode_raw解密接口解密错误
Posted: 2024年 Mar 6日 09:54
by 15158693303
一线长天 2024年 Mar 6日 09:19
代码里没有看到加密相关片段,请提供完整加解密代码片段与日志
你好,上面是完整版的加密解密片段
Re: 【求助】使用aes_inf.h头文件里的aes128_ecb_decode_raw解密接口解密错误
Posted: 2024年 Mar 6日 11:26
by yingtao_33
解密接口没有什么问题,具体示例请参考如下:
Code: Select all
BYTE_T key[] ="6r4mq0ptoan2wf70";
BYTE_T plaintext[] ="l8hpkkjnn93mx0pe";
BYTE_T ciphertext[32] ;
BYTE_T decodetext[32] ;
UINT_T i = 0;
memset(ciphertext, 0x00, SIZEOF(ciphertext));
aes128_ecb_encode_raw(plaintext, strlen(plaintext), ciphertext, key);
TAL_PR_NOTICE("AES_EN1: ");
TAL_PR_NOTICE("ciphertext: ");
for(i = 0; i<strlen(ciphertext); i++){
TAL_PR_DEBUG_RAW("%02X ", ciphertext[i]);
}
TAL_PR_DEBUG_RAW("\r\n");
memset(decodetext, 0x00, SIZEOF(decodetext));
aes128_ecb_decode_raw(ciphertext, strlen(ciphertext), decodetext, key);
TAL_PR_NOTICE("AES_DE1: ");
TAL_PR_NOTICE("decodetext: %s", decodetext);
对应的日志打印如下:
Re: 【求助】使用aes_inf.h头文件里的aes128_ecb_decode_raw解密接口解密错误
Posted: 2024年 Mar 6日 13:30
by 15158693303
Re: 【已解决】使用aes_inf.h头文件里的aes128_ecb_decode_raw解密接口解密错误
Posted: 2024年 Mar 7日 09:26
by 15158693303
你好,这段解密始终解出来的是乱码。能帮我看下什么情况吗?
Code: Select all
BYTE_T data1[] ="b4046667e3c549673aa75369b605f342";
BYTE_T datakey1[] ="6r4mq0ptoan2wf70";
BYTE_T outdata1[32] = {0};
BYTE_T dedataget[32] = {0};
BYTE_T cat[8];
memset(dedataget,0x00,32);
int ii = aes128_ecb_decode_raw(data1, strlen(data1), outdata1, datakey1);
TAL_PR_INFO("ii;%d", ii);
TAL_PR_INFO("data1;%s", data1);
TAL_PR_INFO("strlen(data1);%d", strlen(data1));
TAL_PR_INFO("outdata1;%s", outdata1);
TAL_PR_INFO("outlen1;%d", outlen1);
TAL_PR_INFO("strlen(outdata1);%d", strlen(outdata1));
TAL_PR_INFO("datakey1;%s", datakey1);
TAL_PR_INFO("outdata1;%s", outdata1);
aes_free_data(outdata1);
Re: 【已解决】使用aes_inf.h头文件里的aes128_ecb_decode_raw解密接口解密错误
Posted: 2024年 Mar 7日 09:28
by 15158693303
15158693303 2024年 Mar 7日 09:26
你好,这段解密始终解出来的是乱码。能帮我看下什么情况吗?
Code: Select all
BYTE_T data1[] ="b4046667e3c549673aa75369b605f342";
BYTE_T datakey1[] ="6r4mq0ptoan2wf70";
BYTE_T outdata1[32] = {0};
BYTE_T dedataget[32] = {0};
BYTE_T cat[8];
memset(dedataget,0x00,32);
int ii = aes128_ecb_decode_raw(data1, strlen(data1), outdata1, datakey1);
TAL_PR_INFO("ii;%d", ii);
TAL_PR_INFO("data1;%s", data1);
TAL_PR_INFO("strlen(data1);%d", strlen(data1));
TAL_PR_INFO("outdata1;%s", outdata1);
TAL_PR_INFO("outlen1;%d", outlen1);
TAL_PR_INFO("strlen(outdata1);%d", strlen(outdata1));
TAL_PR_INFO("datakey1;%s", datakey1);
TAL_PR_INFO("outdata1;%s", outdata1);
aes_free_data(outdata1);
"b4046667e3c549673aa75369b605f342"这段密文是我服务器下发下来的,密钥目前是固定"6r4mq0ptoan2wf70"。我需要先解密。但解密后就是乱码
Re: 【求助】使用aes_inf.h头文件里的aes128_ecb_decode_raw解密接口解密错误
Posted: 2024年 Mar 7日 09:54
by yingtao_33
1.你这个密文是字符串格式,你应该先将字符串转成Hex,然后再调用解密接口。如下图
2.另外 outdata1 是你申请的局部数组 不需要调用 aes_free_data(outdata1)进行额外的释放 。
Re: 【求助】使用aes_inf.h头文件里的aes128_ecb_decode_raw解密接口解密错误
Posted: 2024年 Mar 8日 08:25
by 15158693303