| 807 | } |
| 808 | |
| 809 | std::vector<uint8_t> encrypt(const std::string& raw) { |
| 810 | std::vector<uint8_t> data(raw.begin(), raw.end()); |
| 811 | data = pad(data); |
| 812 | std::vector<uint8_t> iv(16); |
| 813 | for (size_t i = 0; i < 16; ++i) iv[i] = rand() % 256; |
| 814 | std::vector<uint8_t> result = iv; |
| 815 | AES_ctx ctx_copy = ctx; |
| 816 | AES_ctx_set_iv(&ctx_copy, iv.data()); |
| 817 | AES_CBC_encrypt_buffer(&ctx_copy, data.data(), data.size()); |
| 818 | result.insert(result.end(), data.begin(), data.end()); |
| 819 | return result; |
| 820 | } |
| 821 | |
| 822 | std::string decrypt(const std::vector<uint8_t>& enc) { |
| 823 | if (enc.size() < 16) throw std::runtime_error("Invalid encrypted data"); |
no test coverage detected