fix:修正加解密BUG。
This commit is contained in:
parent
807dbdfede
commit
6ecf0d419a
@ -42,7 +42,7 @@
|
||||
## 1.程序启动
|
||||
|
||||
- 对于服务端程序`tss`,绑定默认绑定`0.0.0.0`的`9898`端口,如果需要修改端口,使用参数启动,示例:`tss 9898`。
|
||||
- 对于客户端程序`tsc`,请使用`tsc --help`查看使用方式。
|
||||
- 对于客户端程序`tsc`,请使用`tsc --help`查看如何启动。
|
||||
|
||||
## 2.使用
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
CTransProtocal::CTransProtocal() = default;
|
||||
constexpr uint8_t kz = 16;
|
||||
static bool use_encrypt = false;
|
||||
static bool use_encrypt = true;
|
||||
CTransProtocal::~CTransProtocal() = default;
|
||||
|
||||
/*
|
||||
@ -182,15 +182,15 @@ void serialize(CMessageInfo& msg_info, char** out_buf, int& len)
|
||||
ptr += sizeof(int);
|
||||
memcpy(ptr, info.data.data(), o_size);
|
||||
|
||||
char* c = *out_buf;
|
||||
char* mark = *out_buf;
|
||||
if (!use_encrypt) {
|
||||
c[0] = 0x00;
|
||||
mark[0] = 0x00;
|
||||
return;
|
||||
}
|
||||
uint8_t ik[32]{};
|
||||
hash(msg_info.id.c_str(), ik);
|
||||
encrypt(ik, (uint8_t*)(*out_buf + 1), len);
|
||||
c[0] = 0x01;
|
||||
encrypt(ik, (uint8_t*)(*out_buf + 1), len - 1);
|
||||
mark[0] = 0x01;
|
||||
}
|
||||
|
||||
bool deserialize(char* data, int len, CMessageInfo& msg_info)
|
||||
@ -201,13 +201,13 @@ bool deserialize(char* data, int len, CMessageInfo& msg_info)
|
||||
|
||||
auto& info = msg_info;
|
||||
char* ptr = data + kz + 1;
|
||||
uint8_t ie = data[0];
|
||||
uint8_t mark = data[0];
|
||||
int remaining = len;
|
||||
|
||||
if (ie != 0x00) {
|
||||
if (mark != 0x00) {
|
||||
uint8_t ik[32]{};
|
||||
hash(msg_info.id.c_str(), ik);
|
||||
if (!decrypt(ik, (uint8_t*)(data + 1), len)) {
|
||||
if (!decrypt(ik, (uint8_t*)(data + 1), len - 1)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user