#include #include #include #include #include #include "../login.cpp" // 直接复用加密解密相关函数 int main() { std::string username = "test3"; std::string fixed_key = "XNSim_Access_Key"; std::vector key = derive_aes_key(username, fixed_key); for (int access_level = 0; access_level <= 4; ++access_level) { // 加密 std::vector iv; std::vector ciphertext = aes_encrypt(std::to_string(access_level), key, iv); std::vector iv_and_ciphertext = iv; iv_and_ciphertext.insert(iv_and_ciphertext.end(), ciphertext.begin(), ciphertext.end()); std::string hexstr = bin2hex(iv_and_ciphertext); // 解密 std::vector iv_and_ciphertext2 = hex2bin(hexstr); std::vector iv2(iv_and_ciphertext2.begin(), iv_and_ciphertext2.begin() + 16); std::vector ciphertext2(iv_and_ciphertext2.begin() + 16, iv_and_ciphertext2.end()); std::string decrypted = aes_decrypt(ciphertext2, key, iv2); std::cout << "username: " << username << std::endl; std::cout << "access_level: " << access_level << std::endl; std::cout << "加密后16进制: " << hexstr << std::endl; std::cout << "解密还原: " << decrypted << std::endl; std::cout << "-----------------------------" << std::endl; } return 0; }