fix:修正加密iv问题。

This commit is contained in:
taynpg 2025-04-08 23:00:40 +08:00
parent f176c0a8f0
commit d715719a00
2 changed files with 8 additions and 7 deletions

View File

@ -8,19 +8,20 @@ int main()
uint8_t ik[32]{};
hash(key.c_str(), ik);
int offset = 16;
char* msg = new char[256]{};
memset(msg, 0, 256);
auto len = std::snprintf(msg + 12, 256, "%s", "hello world");
std::cout << encrypt(ik, (uint8_t*)msg, len + 12) << std::endl;
std::cout << msg + 12 << std::endl;
auto len = std::snprintf(msg + offset, 256 - offset, "%s", "hello world");
std::cout << encrypt(ik, (uint8_t*)msg, len + offset) << std::endl;
std::cout << msg + offset << std::endl;
uint8_t ik2[32]{};
hash(key.c_str(), ik2);
std::cout << decrypt(ik2, (uint8_t*)msg, len + 12) << std::endl;
std::cout << decrypt(ik2, (uint8_t*)msg, len + offset) << std::endl;
std::cout << msg + 12 << std::endl;
std::cout << msg + offset << std::endl;
return 0;
}

View File

@ -8,7 +8,7 @@
#include <thread>
CTransProtocal::CTransProtocal() = default;
constexpr uint8_t kz = 12;
constexpr uint8_t kz = 16;
CTransProtocal::~CTransProtocal() = default;
/*
@ -309,7 +309,7 @@ bool encrypt(const uint8_t* k, uint8_t* m, size_t len)
}
uint8_t nonce[kz]{};
rdm(nonce, sizeof(nonce));
rdm(nonce, sizeof(nonce) - 4);
memcpy(m, nonce, kz);
struct AES_ctx ctx;