QSslKey Class

QSslKey 类为私钥和公钥提供了一个接口。更多

头文件: #include <QSslKey>
CMake: find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
qmake: QT += network

注意:该类中的所有函数都是可重入的

公共函数

QSslKey()
QSslKey(Qt::HANDLE handle, QSsl::KeyType type = QSsl::PrivateKey)
QSslKey(QIODevice *device, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat encoding = QSsl::Pem, QSsl::KeyType type = QSsl::PrivateKey, const QByteArray &passPhrase = QByteArray())
QSslKey(const QByteArray &encoded, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat encoding = QSsl::Pem, QSsl::KeyType type = QSsl::PrivateKey, const QByteArray &passPhrase = QByteArray())
QSslKey(const QSslKey &other)
~QSslKey()
QSsl::KeyAlgorithm algorithm() const
void clear()
Qt::HANDLE handle() const
bool isNull() const
int length() const
void swap(QSslKey &other)
QByteArray toDer(const QByteArray &passPhrase = QByteArray()) const
QByteArray toPem(const QByteArray &passPhrase = QByteArray()) const
QSsl::KeyType type() const
bool operator!=(const QSslKey &other) const
QSslKey &operator=(const QSslKey &other)
bool operator==(const QSslKey &other) const

详细说明

QSslKey 为管理密钥提供了一个简单的 API。

另请参阅 QSslSocket,QSslCertificate, 和QSslCipher

成员函数文档

QSslKey::QSslKey()

构造一个空键。

另请参阅 isNull().

[explicit] QSslKey::QSslKey(Qt::HANDLE handle, QSsl::KeyType type = QSsl::PrivateKey)

从一个有效的本地密钥handle 构建一个 QSslKey。type 指定密钥是公钥还是私钥。

QSslKey 将拥有该密钥的所有权,因此不得使用本地库释放该密钥。

QSslKey::QSslKey(QIODevice *device, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat encoding = QSsl::Pem, QSsl::KeyType type = QSsl::PrivateKey, const QByteArray &passPhrase = QByteArray())

通过使用指定的algorithmencoding 格式从device 读取和解码数据,构建 QSslKey。type 指定密钥是公开的还是私有的。

如果密钥已加密,则passPhrase 用于解密。

构建完成后,使用isNull() 检查device 是否提供了有效的密钥。

QSslKey::QSslKey(const QByteArray &encoded, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat encoding = QSsl::Pem, QSsl::KeyType type = QSsl::PrivateKey, const QByteArray &passPhrase = QByteArray())

通过使用指定的algorithmencoding 格式解码字节数组encoded 中的字符串,构建 QSslKey。type 指定密钥是公开的还是私有的。

如果密钥已加密,则passPhrase 用于解密。

构建完成后,使用isNull() 检查encoded 是否包含有效的密钥。

QSslKey::QSslKey(const QSslKey &other)

构建一个与other 完全相同的副本。

[noexcept] QSslKey::~QSslKey()

销毁QSslKey 对象。

QSsl::KeyAlgorithm QSslKey::algorithm() const

返回密钥算法。

void QSslKey::clear()

清除此键的内容,使其成为空键。

另请参见 isNull().

Qt::HANDLE QSslKey::handle() const

如果有本地密钥句柄,则返回指向本地密钥句柄的指针,否则返回nullptr

您可以将此句柄与本地 API 结合使用,访问有关密钥的扩展信息。

警告: 使用此函数很可能无法移植,其返回值在不同平台和不同 Qt 小版本之间可能会有所不同。

bool QSslKey::isNull() const

如果此键为空键,则返回true ;否则返回 false。

另请参见 clear().

int QSslKey::length() const

以比特为单位返回密钥的长度,如果密钥为空,则返回-1。

[noexcept] void QSslKey::swap(QSslKey &other)

将此 SSL 密钥与other 互换。该操作速度非常快,从未出现过故障。

QByteArray QSslKey::toDer(const QByteArray &passPhrase = QByteArray()) const

以 DER 编码返回密钥。

由于 DER 无法加密,因此passPhrase 参数应省略。未来的 Qt 版本将删除该参数。

QByteArray QSslKey::toPem(const QByteArray &passPhrase = QByteArray()) const

以 PEM 编码返回密钥。如果密钥是私人密钥,且passPhrase 非空,则用passPhrase 对结果进行加密。

QSsl::KeyType QSslKey::type() const

返回密钥的类型(即 PublicKey 或 PrivateKey)。

bool QSslKey::operator!=(const QSslKey &other) const

如果该键不等于键other ,则返回true ;否则返回false

QSslKey &QSslKey::operator=(const QSslKey &other)

other 的内容复制到此密钥中,使两个密钥完全相同。

返回对QSslKey 的引用。

bool QSslKey::operator==(const QSslKey &other) const

如果该键等于other ,则返回true ;否则返回false

© 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.