| 43 | } |
| 44 | |
| 45 | static bool readHex(const std::string& input, uint8_t* buffer, size_t length) { |
| 46 | if (input.size() != length * 2) { |
| 47 | LOGGER.error("readHex() length mismatch"); |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | char hex[3] = { 0 }; |
| 52 | for (size_t i = 0; i < length; i++) { |
| 53 | hex[0] = input[i * 2]; |
| 54 | hex[1] = input[i * 2 + 1]; |
| 55 | char* endptr; |
| 56 | unsigned long val = strtoul(hex, &endptr, 16); |
| 57 | if (endptr != hex + 2) { |
| 58 | LOGGER.error("readHex() invalid hex character"); |
| 59 | return false; |
| 60 | } |
| 61 | buffer[i] = static_cast<uint8_t>(val); |
| 62 | } |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | static bool encryptKey(const uint8_t key[ESP_NOW_KEY_LEN], std::string& hexOutput) { |
| 67 | uint8_t iv[16]; |