QSslPreSharedKeyAuthenticator Class
QSslPreSharedKeyAuthenticator 类为预共享密钥(PSK)密码套件提供身份验证数据。更多内容...
| 头文件: | #include <QSslPreSharedKeyAuthenticator> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Network) target_link_libraries(mytarget PRIVATE Qt6::Network) |
| qmake: | QT += network |
- 所有成员列表(包括继承的成员)
- QSslPreSharedKeyAuthenticator 属于“网络编程 API”和“隐式共享类”的一部分。
注意:该类中的所有函数均为可重入函数。
公共函数
| QSslPreSharedKeyAuthenticator() | |
| QSslPreSharedKeyAuthenticator(const QSslPreSharedKeyAuthenticator &authenticator) | |
| ~QSslPreSharedKeyAuthenticator() | |
| QByteArray | identity() const |
| QByteArray | identityHint() const |
| int | maximumIdentityLength() const |
| int | maximumPreSharedKeyLength() const |
| QByteArray | preSharedKey() const |
| void | setIdentity(const QByteArray &identity) |
| void | setPreSharedKey(const QByteArray &preSharedKey) |
| void | swap(QSslPreSharedKeyAuthenticator &other) |
| QSslPreSharedKeyAuthenticator & | operator=(QSslPreSharedKeyAuthenticator &&authenticator) |
| QSslPreSharedKeyAuthenticator & | operator=(const QSslPreSharedKeyAuthenticator &authenticator) |
相关的非成员
| bool | operator!=(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs) |
| bool | operator==(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs) |
详细描述
SSL 套接字使用 QSslPreSharedKeyAuthenticator 类在预共享密钥 (PSK) 密码套件中提供所需的身份验证数据。
在 PSK 握手过程中,客户端必须推导出一个密钥,该密钥必须与服务器上设置的密钥相匹配。 推导密钥的确切算法取决于应用程序;但是,为此,服务器可能会向客户端发送一个身份提示。客户端随后将此提示与其他信息(例如密码短语)结合使用,来构建共享密钥。
QSslPreSharedKeyAuthenticator 为客户端应用程序提供了完成 PSK 握手所需的手段。客户端应用程序需要将一个插槽连接到QSslSocket::preSharedKeyAuthenticationRequired() 信号:
connect(socket, &QSslSocket::preSharedKeyAuthenticationRequired,
this, &AuthManager::handlePreSharedKeyAuthentication);该信号携带一个 QSslPreSharedKeyAuthenticator 对象,其中包含服务器发送给客户端的身份提示,该对象必须填充相应的客户端身份和派生密钥:
void AuthManager::handlePreSharedKeyAuthentication(QSslPreSharedKeyAuthenticator *authenticator)
{
authenticator->setIdentity("My Qt App");
const QByteArray key = deriveKey(authenticator->identityHint(), passphrase);
authenticator->setPreSharedKey(key);
}注意: 仅当使用 OpenSSL 1.0.1(或更高版本)作为 SSL 后端时,才支持PSK 密码套件。
注意: 目前仅 OpenSSL 支持PSK 。
另请参阅 QSslSocket 。
成员函数文档
QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator()
构建一个默认的 QSslPreSharedKeyAuthenticator 对象。
身份提示、身份和密钥将被初始化为空字节数组;身份和密钥的最大长度均将被初始化为 0。
QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator(const QSslPreSharedKeyAuthenticator &authenticator)
创建一个 QSslPreSharedKeyAuthenticator 对象,作为authenticator 的副本。
另请参阅 operator=()。
[noexcept] QSslPreSharedKeyAuthenticator::~QSslPreSharedKeyAuthenticator()
销毁QSslPreSharedKeyAuthenticator 对象。
QByteArray QSslPreSharedKeyAuthenticator::identity() const
返回 PSK 客户端标识。
另请参阅 setIdentity()。
QByteArray QSslPreSharedKeyAuthenticator::identityHint() const
返回服务器提供的 PSK 身份提示。该提示的解释由应用程序自行决定。
int QSslPreSharedKeyAuthenticator::maximumIdentityLength() const
返回 PSK 客户端标识的最大长度(以字节为单位)。
注意:可以 设置长度大于 maximumIdentityLength() 的标识;在这种情况下,实际上只会将前 maximumIdentityLength() 字节发送给服务器。
另请参阅 setIdentity()。
int QSslPreSharedKeyAuthenticator::maximumPreSharedKeyLength() const
返回预共享密钥的最大长度(以字节为单位)。
注意:可以 设置长度大于 maximumPreSharedKeyLength() 的密钥;在这种情况下,实际上只会将前 maximumPreSharedKeyLength() 字节发送至服务器。
另请参阅 setPreSharedKey()。
QByteArray QSslPreSharedKeyAuthenticator::preSharedKey() const
返回预共享密钥。
另请参阅 setPreSharedKey()。
void QSslPreSharedKeyAuthenticator::setIdentity(const QByteArray &identity)
将 PSK 客户端标识(将通知给服务器)设置为identity 。
注意:可以 设置长度大于maximumIdentityLength() 的标识;在这种情况下,实际上只会将前maximumIdentityLength() 字节发送给服务器。
另请参阅 identity() 和maximumIdentityLength()。
void QSslPreSharedKeyAuthenticator::setPreSharedKey(const QByteArray &preSharedKey)
将预共享密钥设置为preSharedKey 。
注意:可以 设置长度大于maximumPreSharedKeyLength() 的密钥;在这种情况下,只有前maximumPreSharedKeyLength() 个字节会被实际发送至服务器。
另请参阅 preSharedKey()、maximumPreSharedKeyLength() 和QByteArray::fromHex()。
[noexcept] void QSslPreSharedKeyAuthenticator::swap(QSslPreSharedKeyAuthenticator &other)
将此身份验证器替换为other 。此操作非常快速,且绝不会失败。
[noexcept] QSslPreSharedKeyAuthenticator &QSslPreSharedKeyAuthenticator::operator=(QSslPreSharedKeyAuthenticator &&authenticator)
将QSslPreSharedKeyAuthenticator 对象authenticator 按移动赋值给此对象,并返回被移动实例的引用。
QSslPreSharedKeyAuthenticator &QSslPreSharedKeyAuthenticator::operator=(const QSslPreSharedKeyAuthenticator &authenticator)
将QSslPreSharedKeyAuthenticator 对象authenticator 分配给此对象,并返回该副本的引用。
相关的非成员
bool operator!=(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)
如果身份验证器对象lhs 不等于rhs ,则返回true ;否则返回false 。
bool operator==(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)
如果身份验证器对象lhs 与rhs 相等,则返回 `true `;否则返回 `false `。
两个身份验证器对象相等当且仅当它们具有相同的身份提示、身份、预共享密钥、身份的最大长度以及预共享密钥的最大长度。
© 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.