83 lines
2.4 KiB
C
83 lines
2.4 KiB
C
|
|
#ifndef CONFIGENCRYPTION_H
|
|||
|
|
#define CONFIGENCRYPTION_H
|
|||
|
|
|
|||
|
|
#include <QString>
|
|||
|
|
#include <QByteArray>
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 配置文件加密管理类
|
|||
|
|
*
|
|||
|
|
* 提供配置文件的加密和解密功能,保护配置数据安全
|
|||
|
|
* 使用 AES-256 加密算法
|
|||
|
|
*/
|
|||
|
|
class ConfigEncryption
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
/**
|
|||
|
|
* @brief 加密配置文件内容
|
|||
|
|
* @param plainData 明文数据
|
|||
|
|
* @param password 加密密码
|
|||
|
|
* @return 加密后的数据,如果加密失败返回空
|
|||
|
|
*/
|
|||
|
|
static QByteArray EncryptConfig(const QByteArray& plainData, const QString& password);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 解密配置文件内容
|
|||
|
|
* @param encryptedData 加密数据
|
|||
|
|
* @param password 解密密码
|
|||
|
|
* @return 解密后的明文数据,如果解密失败返回空
|
|||
|
|
*/
|
|||
|
|
static QByteArray DecryptConfig(const QByteArray& encryptedData, const QString& password);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 加密文件
|
|||
|
|
* @param filePath 文件路径
|
|||
|
|
* @param password 加密密码
|
|||
|
|
* @return 成功返回 true,失败返回 false
|
|||
|
|
*/
|
|||
|
|
static bool EncryptFile(const QString& filePath, const QString& password);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 解密文件
|
|||
|
|
* @param filePath 文件路径
|
|||
|
|
* @param password 解密密码
|
|||
|
|
* @return 成功返回 true,失败返回 false
|
|||
|
|
*/
|
|||
|
|
static bool DecryptFile(const QString& filePath, const QString& password);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 验证密码是否正确
|
|||
|
|
* @param encryptedData 加密数据
|
|||
|
|
* @param password 待验证密码
|
|||
|
|
* @return 密码正确返回 true,否则返回 false
|
|||
|
|
*/
|
|||
|
|
static bool VerifyPassword(const QByteArray& encryptedData, const QString& password);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 生成密钥
|
|||
|
|
* @param password 用户密码
|
|||
|
|
* @param salt 盐值
|
|||
|
|
* @return 256位密钥
|
|||
|
|
*/
|
|||
|
|
static QByteArray GenerateKey(const QString& password, const QByteArray& salt);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 设置 Windows 目录权限(仅管理员可访问)
|
|||
|
|
* @param directoryPath 目录路径
|
|||
|
|
* @return 成功返回 true,失败返回 false
|
|||
|
|
*/
|
|||
|
|
static bool SetDirectoryPermissions(const QString& directoryPath);
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
// AES 加密块大小
|
|||
|
|
static const int AES_BLOCK_SIZE = 16;
|
|||
|
|
|
|||
|
|
// 盐值大小
|
|||
|
|
static const int SALT_SIZE = 16;
|
|||
|
|
|
|||
|
|
// 验证标记(用于验证密码)
|
|||
|
|
static const char* MAGIC_HEADER;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
#endif // CONFIGENCRYPTION_H
|