From 72b3084f70533fad838364875a251db82261488e Mon Sep 17 00:00:00 2001 From: YuXifeng <2860280851@qq.com> Date: Mon, 24 Mar 2025 21:46:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E8=A7=A3?= =?UTF-8?q?=E5=AF=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/CMakeLists.txt | 2 +- main/file_system/file_encryptor.c | 8 ++++++++ main/file_system/file_encryptor.h | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 main/file_system/file_encryptor.c create mode 100644 main/file_system/file_encryptor.h diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 8a99507..1e1cd27 100755 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,7 +1,7 @@ file(GLOB PORT_SRCS "wifi/*.c" ) -file(GLOB FILE_SYS_SRCS "file_system/spiffs.c" ) +file(GLOB FILE_SYS_SRCS "file_system/spiffs.c" "file_system/file_encryptor.c" ) idf_component_register(SRCS "main.c" "usb_serial_task" "Receiver.c" ${PORT_SRCS} diff --git a/main/file_system/file_encryptor.c b/main/file_system/file_encryptor.c new file mode 100644 index 0000000..34f90e4 --- /dev/null +++ b/main/file_system/file_encryptor.c @@ -0,0 +1,8 @@ +#include "file_encryptor.h" + +// XOR 加密/解密 +void xor_encrypt_decrypt(uint8_t *data, size_t data_len, const uint8_t *key, size_t key_len) { + for (size_t i = 0; i < data_len; ++i) { + data[i] ^= key[i % key_len]; // 使用密钥进行 XOR 加密/解密 + } +} \ No newline at end of file diff --git a/main/file_system/file_encryptor.h b/main/file_system/file_encryptor.h new file mode 100644 index 0000000..d22ae61 --- /dev/null +++ b/main/file_system/file_encryptor.h @@ -0,0 +1,11 @@ +#ifndef FILE_ENCRYPTOR_H +#define FILE_ENCRYPTOR_H + +#include "esp_log.h" +#include "esp_system.h" + + +// 加密/解密方法:这里我们将使用 XOR 加密 +void xor_encrypt_decrypt(uint8_t *data, size_t data_len, const uint8_t *key, size_t key_len); + +#endif // FILE_ENCRYPTOR_H \ No newline at end of file