我将消息加密到客户端(c ++),使用aes,服务器(C#)对其进行解密。如果发布服务器上的构建调试客户端说如果消息是一个值大于127的变量(int64_t),如果它小于ok则无法解密消息
消息的结构
class version : public ::google::protobuf::Message
{
string* software_;
int64_t version_;
};
我的代码
uint32_t encrypt(const unsigned char *in, unsigned char **out, uint32_t size)
{
/**
* tresh - ivec change after AES_cbc_encrypt
*/
unsigned char _ivec[AES_BLOCK_SIZE];
memcpy(&_ivec, &ivec, AES_BLOCK_SIZE);
/**/
uint32_t size_out = this->getBlockSize(size);
unsigned char *in_padding = (unsigned char*)malloc(size_out);
memset(in_padding, size_out - size, size_out);
memcpy(in_padding, in, size);
AES_KEY _key;
AES_set_encrypt_key(key, PK_SIZE_KEY*BITS_IN_BYTE, &_key);
AES_cbc_encrypt(in_padding, *out, size_out, &_key, _ivec, AES_ENCRYPT);
free(in_padding);
return size_out;
};
uint32_t getBlockSize(uint32_t size)
{
if((size % AES_BLOCK_SIZE) != 0){
size /= AES_BLOCK_SIZE;
size += 1;
size *= AES_BLOCK_SIZE;
}
return size;
};
如何解决?非常奇怪
答案 0 :(得分:0)
更改了代码并确定
uint32_t getBlockSize(uint32_t size)
{
size /= AES_BLOCK_SIZE;
size += 1;
size *= AES_BLOCK_SIZE;
return size;
};