1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
|
#include <cstdint> #include <cstring> #include <cstdio> #include <cstdlib> #include <string> #include <vector> #include <fstream> #include <random> #include <iostream>
static const uint8_t SBOX[256] = { 0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76, 0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0, 0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15, 0x04,0xc7,0x23,0xc3,0x18,0x96,0x05,0x9a,0x07,0x12,0x80,0xe2,0xeb,0x27,0xb2,0x75, 0x09,0x83,0x2c,0x1a,0x1b,0x6e,0x5a,0xa0,0x52,0x3b,0xd6,0xb3,0x29,0xe3,0x2f,0x84, 0x53,0xd1,0x00,0xed,0x20,0xfc,0xb1,0x5b,0x6a,0xcb,0xbe,0x39,0x4a,0x4c,0x58,0xcf, 0xd0,0xef,0xaa,0xfb,0x43,0x4d,0x33,0x85,0x45,0xf9,0x02,0x7f,0x50,0x3c,0x9f,0xa8, 0x51,0xa3,0x40,0x8f,0x92,0x9d,0x38,0xf5,0xbc,0xb6,0xda,0x21,0x10,0xff,0xf3,0xd2, 0xcd,0x0c,0x13,0xec,0x5f,0x97,0x44,0x17,0xc4,0xa7,0x7e,0x3d,0x64,0x5d,0x19,0x73, 0x60,0x81,0x4f,0xdc,0x22,0x2a,0x90,0x88,0x46,0xee,0xb8,0x14,0xde,0x5e,0x0b,0xdb, 0xe0,0x32,0x3a,0x0a,0x49,0x06,0x24,0x5c,0xc2,0xd3,0xac,0x62,0x91,0x95,0xe4,0x79, 0xe7,0xc8,0x37,0x6d,0x8d,0xd5,0x4e,0xa9,0x6c,0x56,0xf4,0xea,0x65,0x7a,0xae,0x08, 0xba,0x78,0x25,0x2e,0x1c,0xa6,0xb4,0xc6,0xe8,0xdd,0x74,0x1f,0x4b,0xbd,0x8b,0x8a, 0x70,0x3e,0xb5,0x66,0x48,0x03,0xf6,0x0e,0x61,0x35,0x57,0xb9,0x86,0xc1,0x1d,0x9e, 0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf, 0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16 };
static inline uint8_t xtime(uint8_t x) { return (uint8_t)((x << 1) ^ ((x >> 7) * 0x1b)); }
static inline uint8_t gmul(uint8_t a, uint8_t b) { uint8_t p = 0; for (int i = 0; i < 8; i++) { if (b & 1) p ^= a; a = xtime(a); b >>= 1; } return p; }
static void key_expansion(const uint8_t key[32], uint8_t rk[15][16]) { uint8_t w[60][4]; for (int i = 0; i < 8; i++) memcpy(w[i], key + i * 4, 4);
uint8_t rcon = 1; for (int i = 8; i < 60; i++) { uint8_t t[4]; memcpy(t, w[i - 1], 4); if (i % 8 == 0) { uint8_t tmp = t[0]; t[0] = t[1]; t[1] = t[2]; t[2] = t[3]; t[3] = tmp; for (int j = 0; j < 4; j++) t[j] = SBOX[t[j]]; t[0] ^= rcon; rcon = xtime(rcon); } else if (i % 8 == 4) { for (int j = 0; j < 4; j++) t[j] = SBOX[t[j]]; } for (int j = 0; j < 4; j++) w[i][j] = (uint8_t)(w[i - 8][j] ^ t[j]); } for (int r = 0; r < 15; r++) memcpy(rk[r], w[r * 4], 16); }
static void add_round_key(uint8_t st[16], const uint8_t rk[16]) { for (int i = 0; i < 16; i++) st[i] ^= rk[i]; }
static void aes_encrypt_block(const uint8_t rk[15][16], uint8_t st[16]) { add_round_key(st, rk[0]); for (int round = 1; round <= 14; round++) { for (int i = 0; i < 16; i++) st[i] = SBOX[st[i]]; uint8_t t; t = st[1]; st[1] = st[5]; st[5] = st[9]; st[9] = st[13]; st[13] = t; t = st[2]; st[2] = st[10]; st[10] = t; t = st[6]; st[6] = st[14]; st[14] = t; t = st[15]; st[15] = st[11]; st[11] = st[7]; st[7] = st[3]; st[3] = t; if (round != 14) { for (int c = 0; c < 4; c++) { uint8_t* p = st + c * 4; uint8_t a0 = p[0], a1 = p[1], a2 = p[2], a3 = p[3]; p[0] = (uint8_t)(gmul(a0, 2) ^ gmul(a1, 3) ^ a2 ^ a3); p[1] = (uint8_t)(a0 ^ gmul(a1, 2) ^ gmul(a2, 3) ^ a3); p[2] = (uint8_t)(a0 ^ a1 ^ gmul(a2, 2) ^ gmul(a3, 3)); p[3] = (uint8_t)(gmul(a0, 3) ^ a1 ^ a2 ^ gmul(a3, 2)); } } add_round_key(st, rk[round]); } }
static std::vector<uint8_t> aes256_cbc_encrypt(const std::vector<uint8_t>& pt, const uint8_t key[32], const uint8_t iv[16]) { uint8_t rk[15][16]; key_expansion(key, rk);
size_t pad = 16 - (pt.size() % 16); std::vector<uint8_t> buf = pt; buf.insert(buf.end(), pad, (uint8_t)pad);
std::vector<uint8_t> ct(buf.size()); uint8_t prev[16]; memcpy(prev, iv, 16);
for (size_t off = 0; off < buf.size(); off += 16) { uint8_t st[16]; for (int i = 0; i < 16; i++) st[i] = (uint8_t)(buf[off + i] ^ prev[i]); aes_encrypt_block(rk, st); memcpy(prev, st, 16); memcpy(&ct[off], st, 16); } return ct; }
static bool parse_hex(const std::string& hex, uint8_t* out, size_t n) { if (hex.size() != n * 2) return false; for (size_t i = 0; i < n; i++) { unsigned v; if (sscanf(hex.c_str() + i * 2, "%2x", &v) != 1) return false; out[i] = (uint8_t)v; } return true; }
static std::string to_hex(const uint8_t* d, size_t n) { static const char* H = "0123456789ABCDEF"; std::string s; s.reserve(n * 2); for (size_t i = 0; i < n; i++) { s += H[d[i] >> 4]; s += H[d[i] & 0xf]; } return s; }
static std::string c_array(const std::string& name, const uint8_t* d, size_t n) { std::string s = "const unsigned char " + name + "[" + std::to_string(n) + "] = {\n"; for (size_t i = 0; i < n; i++) { char buf[16]; snprintf(buf, sizeof(buf), "0x%02x,", d[i]); s += buf; if ((i + 1) % 16 == 0 && i + 1 < n) s += "\n"; } if (n % 16 != 0) s += "\n"; s += "};\n"; return s; }
static std::string gen_c_header(const std::string& guard) { std::string s; s += "/* Auto-generated by aes_tool - AES-256-CBC decryptor (self-contained) */\n"; s += "#ifndef " + guard + "\n"; s += "#define " + guard + "\n\n"; s += "#include <stddef.h>\n\n"; s += "extern const unsigned char g_key[32];\n"; s += "extern const unsigned char g_iv[16];\n\n"; s += "/* Decrypt embedded payload; returns malloc'd buffer, sets *decode_len.\n"; s += " Caller frees the returned pointer. Returns NULL on failure. */\n"; s += "unsigned char* decrypt_data(int* decode_len);\n\n"; s += "/* Decrypt arbitrary ciphertext buffer into caller-supplied out buffer. */\n"; s += "int decrypt_buffer_core(const unsigned char* cipher, int cipher_len,\n"; s += " unsigned char* out);\n\n"; s += "#endif /* " + guard + " */\n"; return s; }
static std::string gen_c_source(const uint8_t key[32], const uint8_t iv[16], const uint8_t* ct, size_t ctlen) { std::string s; s += "/* Auto-generated by aes_tool - AES-256-CBC decryptor (self-contained) */\n"; s += "#include <stdlib.h>\n"; s += "#include <string.h>\n"; s += "#include \"" ; s += "DECRYPT_H_NAME"; s += "\"\n\n"; s += c_array("g_key", key, 32); s += c_array("g_iv", iv, 16); s += c_array("g_encrypt_data", ct, ctlen); s += "\n"; s += R"CPP( static const unsigned char SBOX[256] = { 0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76, 0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0, 0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15, 0x04,0xc7,0x23,0xc3,0x18,0x96,0x05,0x9a,0x07,0x12,0x80,0xe2,0xeb,0x27,0xb2,0x75, 0x09,0x83,0x2c,0x1a,0x1b,0x6e,0x5a,0xa0,0x52,0x3b,0xd6,0xb3,0x29,0xe3,0x2f,0x84, 0x53,0xd1,0x00,0xed,0x20,0xfc,0xb1,0x5b,0x6a,0xcb,0xbe,0x39,0x4a,0x4c,0x58,0xcf, 0xd0,0xef,0xaa,0xfb,0x43,0x4d,0x33,0x85,0x45,0xf9,0x02,0x7f,0x50,0x3c,0x9f,0xa8, 0x51,0xa3,0x40,0x8f,0x92,0x9d,0x38,0xf5,0xbc,0xb6,0xda,0x21,0x10,0xff,0xf3,0xd2, 0xcd,0x0c,0x13,0xec,0x5f,0x97,0x44,0x17,0xc4,0xa7,0x7e,0x3d,0x64,0x5d,0x19,0x73, 0x60,0x81,0x4f,0xdc,0x22,0x2a,0x90,0x88,0x46,0xee,0xb8,0x14,0xde,0x5e,0x0b,0xdb, 0xe0,0x32,0x3a,0x0a,0x49,0x06,0x24,0x5c,0xc2,0xd3,0xac,0x62,0x91,0x95,0xe4,0x79, 0xe7,0xc8,0x37,0x6d,0x8d,0xd5,0x4e,0xa9,0x6c,0x56,0xf4,0xea,0x65,0x7a,0xae,0x08, 0xba,0x78,0x25,0x2e,0x1c,0xa6,0xb4,0xc6,0xe8,0xdd,0x74,0x1f,0x4b,0xbd,0x8b,0x8a, 0x70,0x3e,0xb5,0x66,0x48,0x03,0xf6,0x0e,0x61,0x35,0x57,0xb9,0x86,0xc1,0x1d,0x9e, 0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf, 0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16 };
static unsigned char xtime(unsigned char x) { return (unsigned char)((x << 1) ^ ((x >> 7) * 0x1b)); }
static unsigned char gmul(unsigned char a, unsigned char b) { unsigned char p = 0; for (int i = 0; i < 8; i++) { if (b & 1) p ^= a; a = xtime(a); b >>= 1; } return p; }
static void key_expansion(const unsigned char key[32], unsigned char rk[15][16]) { // FIPS-197 字级密钥扩展 (Nk=8) unsigned char w[60][4]; for (int i = 0; i < 8; i++) memcpy(w[i], key + i * 4, 4); unsigned char rcon = 1; for (int i = 8; i < 60; i++) { unsigned char t[4]; memcpy(t, w[i - 1], 4); if (i % 8 == 0) { unsigned char tmp = t[0]; t[0] = t[1]; t[1] = t[2]; t[2] = t[3]; t[3] = tmp; for (int j = 0; j < 4; j++) t[j] = SBOX[t[j]]; t[0] ^= rcon; rcon = xtime(rcon); } else if (i % 8 == 4) { for (int j = 0; j < 4; j++) t[j] = SBOX[t[j]]; } for (int j = 0; j < 4; j++) w[i][j] = (unsigned char)(w[i - 8][j] ^ t[j]); } for (int r = 0; r < 15; r++) memcpy(rk[r], w[r * 4], 16); }
static void inv_sub_bytes(unsigned char st[16]) { /* inverse table built at first use */ static unsigned char inv[256]; static int init = 0; if (!init) { for (int i = 0; i < 256; i++) inv[SBOX[i]] = (unsigned char)i; init = 1; } for (int i = 0; i < 16; i++) st[i] = inv[st[i]]; }
static void inv_shift_rows(unsigned char st[16]) { unsigned char t; t = st[13]; st[13] = st[9]; st[9] = st[5]; st[5] = st[1]; st[1] = t; t = st[2]; st[2] = st[10]; st[10] = t; t = st[6]; st[6] = st[14]; st[14] = t; t = st[3]; st[3] = st[7]; st[7] = st[11]; st[11] = st[15]; st[15] = t; }
static void inv_mix_columns(unsigned char st[16]) { for (int c = 0; c < 4; c++) { unsigned char* p = st + c * 4; unsigned char a0 = p[0], a1 = p[1], a2 = p[2], a3 = p[3]; p[0] = (unsigned char)(gmul(a0,14) ^ gmul(a1,11) ^ gmul(a2,13) ^ gmul(a3, 9)); p[1] = (unsigned char)(gmul(a0, 9) ^ gmul(a1,14) ^ gmul(a2,11) ^ gmul(a3,13)); p[2] = (unsigned char)(gmul(a0,13) ^ gmul(a1, 9) ^ gmul(a2,14) ^ gmul(a3,11)); p[3] = (unsigned char)(gmul(a0,11) ^ gmul(a1,13) ^ gmul(a2, 9) ^ gmul(a3,14)); } }
static void aes_decrypt_block(const unsigned char rk[15][16], unsigned char st[16]) { for (int i = 0; i < 16; i++) st[i] ^= rk[14][i]; for (int round = 13; round >= 0; round--) { inv_shift_rows(st); inv_sub_bytes(st); for (int i = 0; i < 16; i++) st[i] ^= rk[round][i]; if (round != 0) inv_mix_columns(st); } }
int decrypt_buffer_core(const unsigned char* cipher, int cipher_len, unsigned char* out) { if (!cipher || !out || cipher_len <= 0 || (cipher_len % 16) != 0) return -1; unsigned char rk[15][16]; key_expansion(g_key, rk);
unsigned char prev[16]; memcpy(prev, g_iv, 16); int blocks = cipher_len / 16; for (int b = 0; b < blocks; b++) { unsigned char st[16], cipherblk[16]; memcpy(cipherblk, cipher + b * 16, 16); memcpy(st, cipherblk, 16); aes_decrypt_block(rk, st); for (int i = 0; i < 16; i++) out[b * 16 + i] = (unsigned char)(st[i] ^ prev[i]); memcpy(prev, cipherblk, 16); } /* strip PKCS#7 padding */ int pad = out[cipher_len - 1]; if (pad < 1 || pad > 16 || pad > cipher_len) return cipher_len; for (int i = 0; i < pad; i++) if (out[cipher_len - 1 - i] != (unsigned char)pad) return cipher_len; return cipher_len - pad; }
unsigned char* decrypt_data(int* decode_len) { int n = (int)sizeof(g_encrypt_data); unsigned char* buf = (unsigned char*)malloc(n); if (!buf) return NULL; int plain = decrypt_buffer_core(g_encrypt_data, n, buf); if (plain < 0) { free(buf); return NULL; } if (decode_len) *decode_len = plain; return buf; } )CPP"; return s; }
static std::string gen_python(const uint8_t key[32], const uint8_t iv[16], const uint8_t* ct, size_t ctlen) { std::string s; s += "# Auto-generated by aes_tool - AES-256-CBC decryptor\n"; s += "# 用法: python3 " ; s += "PLACEHOLDER"; s += "\n#\n# 依赖: pip install pycryptodome (或 cryptography)\n\n"; s += "import sys\n\n"; s += "KEY = bytes.fromhex(\n \"" + to_hex(key, 32) + "\"\n)\n\n"; s += "IV = bytes.fromhex(\n \"" + to_hex(iv, 16) + "\"\n)\n\n"; s += "CIPHERTEXT = bytes.fromhex(\n"; for (size_t i = 0; i < ctlen; i += 32) { size_t n = std::min<size_t>(32, ctlen - i); s += " \"" + to_hex(ct + i, n) + "\"\n"; } s += ")\n\n"; s += R"CPP( def decrypt(key: bytes, iv: bytes, data: bytes) -> bytes: """AES-256-CBC 解密, 自动去除 PKCS#7 填充""" # 优先使用 pycryptodome try: from Crypto.Cipher import AES raw = AES.new(key, AES.MODE_CBC, iv).decrypt(data) except ImportError: # 回退到 cryptography from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend dec = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend()) raw = dec.decryptor().update(data) + dec.decryptor().finalize() # 去 PKCS#7 pad = raw[-1] if 1 <= pad <= 16: return raw[:-pad] return raw
if __name__ == "__main__": plain = decrypt(KEY, IV, CIPHERTEXT) out = sys.argv[1] if len(sys.argv) > 1 else None if out: with open(out, "wb") as f: f.write(plain) print(f"[+] {len(plain)} bytes -> {out}") else: sys.stdout.buffer.write(plain) )CPP"; return s; }
static void replace_all(std::string& s, const std::string& from, const std::string& to) { size_t pos = 0; while ((pos = s.find(from, pos)) != std::string::npos) { s.replace(pos, from.size(), to); pos += to.size(); } }
static void usage(const char* argv0) { fprintf(stderr, "用法: %s -i <输入文件> [选项]\n" "\n" " -i, --input <file> 要加密的输入文件 (必填)\n" " -o, --out <file> 加密输出文件 (默认 <input>.enc)\n" " -k, --key <hex64> 32 字节 AES-256 密钥 (hex), 省略则随机生成\n" " -iv, --iv <hex32> 16 字节 IV (hex), 省略则随机生成\n" " -O, --outdir <dir> 解密器代码生成目录 (默认当前目录)\n" " --cname <name> 生成文件的基名 (默认 crypto_decrypt)\n" " -h, --help 显示帮助\n", argv0); }
int main(int argc, char** argv) { std::string in, out, keyhex, ivhex, outdir = ".", cname = "crypto_decrypt";
for (int i = 1; i < argc; i++) { std::string a = argv[i]; if (a == "-i" || a == "--input") in = argv[++i]; else if (a == "-o" || a == "--out") out = argv[++i]; else if (a == "-k" || a == "--key") keyhex = argv[++i]; else if (a == "-iv" || a == "--iv") ivhex = argv[++i]; else if (a == "-O" || a == "--outdir") outdir = argv[++i]; else if (a == "--cname") cname = argv[++i]; else if (a == "-h" || a == "--help") { usage(argv[0]); return 0; } else { fprintf(stderr, "未知参数: %s\n", a.c_str()); usage(argv[0]); return 1; } }
if (in.empty()) { usage(argv[0]); return 1; } if (out.empty()) out = in + ".enc";
std::ifstream f(in, std::ios::binary); if (!f) { fprintf(stderr, "无法打开输入文件: %s\n", in.c_str()); return 1; } std::vector<uint8_t> pt((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
uint8_t key[32], iv[16]; std::mt19937_64 rng(std::random_device{}()); if (keyhex.empty()) { for (int i = 0; i < 32; i++) key[i] = (uint8_t)(rng() & 0xff); } else if (!parse_hex(keyhex, key, 32)) { fprintf(stderr, "密钥格式错误: 需要 64 个 hex 字符 (32 字节)\n"); return 1; } if (ivhex.empty()) { for (int i = 0; i < 16; i++) iv[i] = (uint8_t)(rng() & 0xff); } else if (!parse_hex(ivhex, iv, 16)) { fprintf(stderr, "IV 格式错误: 需要 32 个 hex 字符 (16 字节)\n"); return 1; }
std::vector<uint8_t> ct = aes256_cbc_encrypt(pt, key, iv);
std::ofstream fo(out, std::ios::binary); fo.write((const char*)ct.data(), ct.size()); fo.close();
std::string hpath = outdir + "/" + cname + ".h"; std::string cpath = outdir + "/" + cname + ".c"; std::string ppath = outdir + "/" + cname + "_dec.py"; std::string guard = cname + "_H";
std::string h = gen_c_header(guard); std::ofstream fh(hpath); fh << h; fh.close();
std::string c = gen_c_source(key, iv, ct.data(), ct.size()); replace_all(c, "DECRYPT_H_NAME", cname + ".h"); std::ofstream fc(cpath); fc << c; fc.close();
std::string p = gen_python(key, iv, ct.data(), ct.size()); replace_all(p, "PLACEHOLDER", cname + "_dec.py"); std::ofstream fp(ppath); fp << p; fp.close();
printf("\n\033[1;36m========================================\033[0m\n"); printf("\033[1;36m AES-256-CBC 加密完成\033[0m\n"); printf("\033[1;36m========================================\033[0m\n"); printf(" 算法 : AES-256-CBC + PKCS#7\n"); printf(" 输入 : %s (%zu 字节)\n", in.c_str(), pt.size()); printf(" 密文 : %s (%zu 字节)\n", out.c_str(), ct.size()); printf(" KEY (32B) : %s\n", to_hex(key, 32).c_str()); printf(" IV (16B) : %s\n", to_hex(iv, 16).c_str()); printf("\n 生成文件:\n"); printf(" C 头文件 : %s\n", hpath.c_str()); printf(" C 实现 : %s\n", cpath.c_str()); printf(" Python : %s\n", ppath.c_str()); printf("\n 下一步 (SGN 编码):\n"); printf(" sgn -i %s -o %s.sgn -a 64 -c 2 --badchars '\\x00'\n", out.c_str(), out.c_str()); printf("\033[1;36m========================================\033[0m\n\n"); return 0; }
|