QOpcUaKeyPair Class

QOpcUaKeyPair 可处理私钥和公钥对。更多

头文件: #include <QOpcUaKeyPair>
CMake: find_package(Qt6 REQUIRED COMPONENTS OpcUa)
target_link_libraries(mytarget PRIVATE Qt6::OpcUa)
qmake: QT += opcua
继承: QObject

公共类型

enum class Cipher { Aes128Cbc, Unencrypted }
enum class KeyType { Rsa, Empty, Unknown }
enum class RsaKeyStrength { Bits1024, Bits2048, Bits4096 }

公共函数

QOpcUaKeyPair(QObject *parent = nullptr)
virtual ~QOpcUaKeyPair()
void generateRsaKey(QOpcUaKeyPair::RsaKeyStrength strength)
bool hasPrivateKey() const
bool loadFromPemData(const QByteArray &data)
QByteArray privateKeyToByteArray(QOpcUaKeyPair::Cipher cipher, const QString &password) const
QByteArray publicKeyToByteArray() const
QOpcUaKeyPair::KeyType type() const

信号

void passphraseNeeded(QString &passphrase, int maximumLength, bool writeOperation)

详细说明

该类目前为技术预览版,因此其提供的 API 和功能可能会随时更改,恕不另行通知。

它可以生成、加载和存储用于非对称加密的密钥。该类的实例必须传递给需要密钥的函数。

成员类型文档

enum class QOpcUaKeyPair::Cipher

用于加密私人密钥的密码。

常数说明
QOpcUaKeyPair::Cipher::Aes128Cbc0用 CBC 加密 AES128
QOpcUaKeyPair::Cipher::Unencrypted1不对密钥加密。

enum class QOpcUaKeyPair::KeyType

该枚举类型指定键的类型。

常量描述
QOpcUaKeyPair::KeyType::Rsa0RSA 密钥
QOpcUaKeyPair::KeyType::Empty1无密钥。
QOpcUaKeyPair::KeyType::Unknown2未处理密钥类型。

enum class QOpcUaKeyPair::RsaKeyStrength

该枚举类型指定 RSA 密钥的强度。

常数描述
QOpcUaKeyPair::RsaKeyStrength::Bits102410241024 位密钥强度。
QOpcUaKeyPair::RsaKeyStrength::Bits204820482048 位密钥强度。
QOpcUaKeyPair::RsaKeyStrength::Bits409640964096 位密钥强度。

成员函数文档

QOpcUaKeyPair::QOpcUaKeyPair(QObject *parent = nullptr)

创建新的空键对,父对象为parent

[virtual noexcept] QOpcUaKeyPair::~QOpcUaKeyPair()

销毁配对密钥。

void QOpcUaKeyPair::generateRsaKey(QOpcUaKeyPair::RsaKeyStrength strength)

生成新的非对称 RSA 密钥对。

密钥长度由strength 指定。

bool QOpcUaKeyPair::hasPrivateKey() const

如果当前密钥包含私钥,则返回true ,否则返回false

bool QOpcUaKeyPair::loadFromPemData(const QByteArray &data)

data 中的 PEM 编码数据加载密钥。成功时返回true ,否则返回false

它可从 PEM 标头检测数据是否包含私钥或公钥。加载加密密钥的方法是将一个函数连接到信号passphraseNeeded ,以提供口令。

[signal] void QOpcUaKeyPair::passphraseNeeded(QString &passphrase, int maximumLength, bool writeOperation)

当私钥需要passphrase 来加密或解密时,就会发出该信号。

writeOperation 当导出密钥需要口令时, ;当导入密钥需要口令时, 。true false

maximumLength 指定口令的最大长度(以字节为单位)。 中超过此限制的所有字符都将被忽略。passphrase

如果使用此信号跨越线程边界,则必须将其与Qt::BlockingQueuedConnection 连接。

QByteArray QOpcUaKeyPair::privateKeyToByteArray(QOpcUaKeyPair::Cipher cipher, const QString &password) const

返回 PEM 编码的私人密钥。如果没有私人密钥,则返回空字节数组。

密钥的加密必须通过参数cipherpassword 来指定。要存储未加密的密钥,必须使用密码Cipher::Unencrypted

QByteArray QOpcUaKeyPair::publicKeyToByteArray() const

以字节数组形式返回公钥。

QOpcUaKeyPair::KeyType QOpcUaKeyPair::type() const

返回当前按键的类型。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.