Qt Open Source Works 35-Key Generator

1. Preface

In many commercial software, you need to provide some versions that can be run on trial, so you need a matching key mechanism to control. Throughout most trial software, you basically use the following mechanisms to control.

  • Remote networking activation, networking every time you start to view the usage time, etc. This method is the most perfect, the disadvantage is that devices that cannot be networked will stop eating.
  • By getting the number of local hard disk + CPU and other hardware, do an operation to generate an activation code. More than half of the software will use this method. The disadvantage is that it is not free to control other parameters of the software, such as the number of devices added to the software.
  • Set a key file with run-to-expire time + quantity limit + run-time, and send it to the user's supporting software. The disadvantage is that if only run-to-expire time is set, the user can change the computer's time to get a longer usage time when the computer is not connected to the network. This demo is implemented by a third method, using the simplest exclusive or encryption method for key files, which can be changed to other encryption methods by itself.

2. Code ideas

QString frmMain::getWMIC(const QString &cmd)
    //Get the cpu name: wmic cpu get Name
    //Get the number of cpu cores: wmic cpu get NumberOfCores
    //Get the number of cpu threads: wmic cpu get NumberOfLogicalProcessors
    //Query cpu serial number: wmic cpu get processorid
    //Query motherboard serial number: wmic baseboard get serialnumber
    //Query BIOS serial number: wmic bios get serialnumber
    //View the hard disk: wmic diskdrive get serialnumber
    QProcess p;
    QString result = QString::fromLocal8Bit(p.readAllStandardOutput());
    QStringList list = cmd.split(" ");
    result = result.remove(list.last(), Qt::CaseInsensitive);
    result = result.replace("\r", "");
    result = result.replace("\n", "");
    result = result.simplified();
    return result;

QString frmMain::getCpuName()
    return getWMIC("wmic cpu get name");

QString frmMain::getCpuId()
    return getWMIC("wmic cpu get processorid");

QString frmMain::getDiskNum()
    return getWMIC("wmic diskdrive where index=0 get serialnumber");

QString frmMain::getXorEncryptDecrypt(const QString &data, char key)
    //Using exclusive or encryption, you can also change the algorithm yourself
    QByteArray buffer = data.toLatin1();
    int size = buffer.size();
    for (int i = 0; i < size; i++) {
        buffer[i] = buffer.at(i) ^ key;

    return QLatin1String(buffer);

void frmMain::on_btnOk_clicked()
    bool useDate = ui->ckDate->isChecked();
    bool useRun = ui->ckRun->isChecked();
    bool useCount = ui->ckCount->isChecked();

    if (!useDate && !useRun && !useCount) {
        if (QMessageBox::question(this, "inquiry", "Are you sure you want to generate keys without any restrictions?") != QMessageBox::Yes) {

    QString strDate = ui->dateEdit->date().toString("yyyy-MM-dd");
    QString strRun = ui->cboxMin->currentText();
    QString strCount = ui->cboxCount->currentText();
    QString key = QString("%1|%2|%3|%4|%5|%6").arg(useDate).arg(strDate).arg(useRun).arg(strRun).arg(useCount).arg(strCount);

    QFile file(QApplication::applicationDirPath() + "/key.db");
    file.open(QFile::WriteOnly | QIODevice::Text);
    file.write(getXorEncryptDecrypt(key, 110).toLatin1());
    QMessageBox::information(this, "Tips", "Successful key generation,take key.db Copy the file to the corresponding directory!");

3. Effect Charts

4. Open Source Home Page

The complete source downloads of the above works are all on the open source homepage. The quantity and quality of the works will be continuously updated, and you are welcome to pay attention.

  1. Domestic site: https://gitee.com/feiyangqingyun/QWidgetDemo
  2. International site: https://github.com/feiyangqingyun/QWidgetDemo
  3. Personal home page: https://blog.csdn.net/feiyangqingyun
  4. Knowing Home Page: https://www.zhihu.com/people/feiyangqingyun/

Tags: network Qt github

Posted on Wed, 17 Jun 2020 21:01:39 -0400 by assonitis