94 lines
2.4 KiB
C
94 lines
2.4 KiB
C
|
|
#ifndef LICENSEMANAGER_H
|
|||
|
|
#define LICENSEMANAGER_H
|
|||
|
|
|
|||
|
|
#include <QString>
|
|||
|
|
#include <QDialog>
|
|||
|
|
#include <QLineEdit>
|
|||
|
|
#include <QPushButton>
|
|||
|
|
#include <QLabel>
|
|||
|
|
#include <QObject>
|
|||
|
|
|
|||
|
|
// ==================== 激活系统设计说明 ====================
|
|||
|
|
// 激活文件后缀: .gal (Geton Again License)
|
|||
|
|
// 激活文件内容: 一行加密字符串
|
|||
|
|
// 加密前格式: "UUID:数字密码"
|
|||
|
|
//
|
|||
|
|
// 加密方式(多层混淆):
|
|||
|
|
// 1. SHA256哈希校验头(8字节)
|
|||
|
|
// 2. XOR密钥加密
|
|||
|
|
// 3. 非线性字节置换 (c * 7 + 13) % 256
|
|||
|
|
// 4. 位置相关混淆
|
|||
|
|
// 5. Base64编码
|
|||
|
|
//
|
|||
|
|
// 验证流程:
|
|||
|
|
// 1. 读取激活文件,多层解密
|
|||
|
|
// 2. 校验SHA256哈希确保完整性
|
|||
|
|
// 3. 解析出UUID和密码
|
|||
|
|
// 4. 对比UUID与本机真实UUID
|
|||
|
|
// 5. 验证密码是否等于程序内置密码
|
|||
|
|
// ===========================================================
|
|||
|
|
|
|||
|
|
class LicenseManager : public QObject
|
|||
|
|
{
|
|||
|
|
Q_OBJECT
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
explicit LicenseManager(QObject *parent = nullptr);
|
|||
|
|
|
|||
|
|
// 获取本机主板UUID
|
|||
|
|
static QString getMachineUUID();
|
|||
|
|
|
|||
|
|
// 获取激活文件路径
|
|||
|
|
static QString getLicenseFilePath();
|
|||
|
|
|
|||
|
|
// 加密解密方法
|
|||
|
|
static QString encrypt(const QString &plainText);
|
|||
|
|
static QString decrypt(const QString &encryptedText);
|
|||
|
|
|
|||
|
|
// 生成激活码(供管理员/供应商使用,根据客户设备UUID生成)
|
|||
|
|
static QString generateActivationCode(const QString &uuid);
|
|||
|
|
|
|||
|
|
// 读取并验证激活文件
|
|||
|
|
static bool readAndVerifyLicense();
|
|||
|
|
|
|||
|
|
// 保存激活文件
|
|||
|
|
static bool saveLicenseFile(const QString &activationCode);
|
|||
|
|
|
|||
|
|
// 显示激活对话框
|
|||
|
|
static bool showActivationDialog(QWidget *parent = nullptr);
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
// 加密密钥 (XOR key)
|
|||
|
|
static const QByteArray encryptKey;
|
|||
|
|
|
|||
|
|
// ========== 客户专用密码(根据客户修改此值) ==========
|
|||
|
|
// 不同客户使用不同的密码,写死在程序中
|
|||
|
|
static const QString customerPassword;
|
|||
|
|
// =====================================================
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 激活对话框
|
|||
|
|
class ActivationDialog : public QDialog
|
|||
|
|
{
|
|||
|
|
Q_OBJECT
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
explicit ActivationDialog(QWidget *parent = nullptr);
|
|||
|
|
|
|||
|
|
QString getServerAddress() const;
|
|||
|
|
QString getActivationCode() const;
|
|||
|
|
|
|||
|
|
private slots:
|
|||
|
|
void onConfirmClicked();
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
void setupUI();
|
|||
|
|
|
|||
|
|
QLineEdit *serverEdit;
|
|||
|
|
QLineEdit *codeEdit;
|
|||
|
|
QPushButton *confirmBtn;
|
|||
|
|
QPushButton *cancelBtn;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
#endif // LICENSEMANAGER_H
|