我正在使用 openssl 函数解密一些数据,但解密的最终结果存在一些问题。
EVP_DecryptInit_ex(ctx, EVP_aes_192_cbc(), NULL, myKey, myVector);
int iPos = 0;
EVP_DecryptUpdate(ctx, decryptedData, &outLength, cryptedData,216);
INFO_NET_HEADER * header = (INFO_NET_HEADER)decryptedData;
iPos += outLength;
//...
int nStreamLength = ((header->incoming_audio_len / 16 +1) *16) - 16; //adjusting the length to the block size, incoming_audio_len is a length of the plain audio stream non-crypted data
char *rest = malloc(nStreamLength+48);
char *decryptedStream = malloc(nStreamLength+48);
int size = receiveRemaining(nStreamLength,rest);
memcpy(decryptedStream,0,nStreamLength+48);
EVP_DecryptUpdate(ctx, decryptedStream, &outLength, rest,size);
EVP_DecryptFinal_ex(ctx, decryptedStream+outLength, &loutLength);
我按部分解密,首先我需要解密 200 个字节,因为它们包含一些我需要获取和接收这些数据的名称和数据长度。前 200 个字节和其余数据都使用相同的密钥进行加密。然后我获取需要解密以接收完整流的数据量,我成功接收了这些数据,一切都很好,但是在输出缓冲区中,最后总是会留下一些垃圾,例如“somedataend\x14\x14\ x14..." 等,垃圾大小从 14 到 16 字节长度,这是 EVP openssl 函数的正常行为吗?