Files
bishe-STM32/Hardware/Crypto.h
T
2026-05-01 20:29:02 +08:00

31 lines
821 B
C

#ifndef _CRYPTO_H_
#define _CRYPTO_H_
#include <stdint.h>
#include <stddef.h>
/**
* @brief 加密JSON数据
* @param json_data 原始JSON字符串
* @param encrypted_output 输出的加密Base64字符串(需要预分配足够空间)
* @return 加密后的Base64字符串长度
*
* 注意:encrypted_output缓冲区至少需要 (strlen(json_data) / 16 + 1) * 16 * 4/3 + 10 字节
*/
uint32_t Crypto_EncryptJSON(const char* json_data, char* encrypted_output);
/**
* @brief 获取加密后数据的最大长度
* @param json_length JSON字符串长度
* @return 加密后的最大长度
*/
#define CRYPTO_MAX_ENCRYPTED_SIZE(json_len) (((json_len) / 16 + 1) * 16 * 4 / 3 + 10)
/**
* @brief 初始化加密模块
* 设置密钥和IV(初始化向量)
*/
void Crypto_Init(void);
#endif // _CRYPTO_H_