0

我需要使用 Qt 用 gpg 加密一些文本。QCA 是别无选择。我的函数在 Linux 中运行,但在 Windows 中我得到了 exitCode 2。

在命令行上使用相同的参数执行 gpg2.exe 就像预期的那样工作。

QString PGPProcess::encrypt(QString toAddress, QString message)
{

    this->start(QStringList() << "--trust-model always" << "-a" << "-e" << "-r " + toAddress);
    this->waitForStarted(PROCESS_WAIT);
    this->write(message.toUtf8());
    this->waitForBytesWritten(PROCESS_WAIT);
    this->closeWriteChannel();
    this->waitForFinished(PROCESS_WAIT);

    if(this->exitCode()) {
        qDebug() << this->exitCode();
        return message;
    } else {
        return this->readAllStandardOutput();
    }

}

我认为这与 closeWriteChannel() 有关。命令行必须发送 gpg 正在加密书面文本的 CRTL-D (Linux)。

在 Windows 中 CTRL-D 不做任何事情,我必须按 CTRL-C。但是在 QProcess 上调用 terminate() 也不起作用。

4

1 回答 1

0

好的,只需将参数 QStringList 更改为以下即可...

this->start(QStringList() << "--trust-model" << "always" << "-a" << "-e" << "-r" << toAddress);
于 2015-10-31T15:02:43.497 回答