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) |
成员类型文档
enum class QOpcUaKeyPair::Cipher
用于加密私钥的密码算法。
| 常量 | 值 | 描述 |
|---|---|---|
QOpcUaKeyPair::Cipher::Aes128Cbc | 0 | 使用 CBC 模式加密 AES128 |
QOpcUaKeyPair::Cipher::Unencrypted | 1 | 密钥不会被加密。 |
enum class QOpcUaKeyPair::KeyType
此枚举类型指定了键的类型。
| 常量 | 值 | 描述 |
|---|---|---|
QOpcUaKeyPair::KeyType::Rsa | 0 | 一个 RSA 密钥 |
QOpcUaKeyPair::KeyType::Empty | 1 | 没有可用的密钥。 |
QOpcUaKeyPair::KeyType::Unknown | 2 | 不支持该类型的密钥。 |
enum class QOpcUaKeyPair::RsaKeyStrength
此枚举类型指定了 RSA 密钥的强度。
| 常量 | 值 | 描述 |
|---|---|---|
QOpcUaKeyPair::RsaKeyStrength::Bits1024 | 1024 | 1024 位的密钥强度。 |
QOpcUaKeyPair::RsaKeyStrength::Bits2048 | 2048 | 密钥强度为 2048 位。 |
QOpcUaKeyPair::RsaKeyStrength::Bits4096 | 4096 | 4096 位的密钥强度。 |
成员函数文档
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 编码的私钥。如果没有私钥,则返回一个空字节数组。
必须使用参数cipher 和password 指定密钥的加密方式。若要以未加密形式存储密钥,则必须使用加密算法Cipher::Unencrypted 。
QByteArray QOpcUaKeyPair::publicKeyToByteArray() const
返回公共密钥,格式为字节数组。
QOpcUaKeyPair::KeyType QOpcUaKeyPair::type() const
返回当前键的类型。
© 2026 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.