使用上层秘钥解密终端识别码密钥后再次加密连接设备

This commit is contained in:
lnk
2025-07-28 10:40:00 +08:00
parent d58923fd21
commit 492193f848
4 changed files with 75 additions and 4 deletions

View File

@@ -56,6 +56,8 @@ extern char* POSTGRES_TABLEPREFIX;
void GetSM4Code(unsigned char* pSerise,char* pKey,char* output);
void MyGetSM4Code(char* input,unsigned char* szKey,char* output);
int sm4_ecb_decrypt_zeropad_base64(const char* base64_cipher, const char* key_str, char* plaintext_out);//lnk20250728
void try_start_kafka_thread();
void try_start_mqconsumer_thread();//lnk20241216
@@ -149,6 +151,8 @@ int parse_device_cfg_web();
int parse_model_cfg_web();
void SOEFileWeb(char* localpath,char* cloudpath,char* wavepath);
const char* get_front_msg_from_subdir();
//////////////////////////////////////////////////////////////////////////////////////
typedef struct {
char WavePhasicFlag[64];

View File

@@ -218,8 +218,6 @@ int main(int argc, const char **argv)
return rv;
}
getVersion(argc,argv);
rv=parse_param(argc, argv);

View File

@@ -1182,7 +1182,23 @@ S_SEC_ENCRYPT_CTRL *encryptCtrl = NULL; /* conn enctryption info */
authInfo->auth_pres = SD_TRUE;
authInfo->mech_type = ACSE_AUTH_MECH_PASSWORD;
memset(ied_password,0,sizeof(ied_password));
GetSM4Code((unsigned char*)dev_series,dev_key,ied_password);
//传进来的就是加密过的先解密成明文再传入
const char* key = "11HDESaAhiHHug2z";//上层使用的写死的key
char dev_series_plaintext[256] = {0};
char dev_key_plaintext[256] = {0};
int ret1 = sm4_ecb_decrypt_zeropad_base64(dev_series, key, dev_series_plaintext);
int ret2 = sm4_ecb_decrypt_zeropad_base64(dev_key, key, dev_key_plaintext);
if (ret1 == 0 && ret2 == 0) {
printf("识别码解密成功\n");
//printf("解密后的 dev_series: %s\n", dev_series_plaintext);
//printf("解密后的 dev_key : %s\n", dev_key_plaintext);
} else {
printf("识别码解密失败\n");
}
GetSM4Code((unsigned char*)dev_series_plaintext,dev_key_plaintext,ied_password);
strcpy (authInfo->u.pw_auth.password, ied_password);
} else {
printf("dev_series or dev_key is null or space!\n");