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

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

@@ -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");