En esta página

QSslPreSharedKeyAuthenticator Class

La clase `QSslPreSharedKeyAuthenticator` proporciona datos de autenticación para conjuntos de cifrado con claves precompartidas (PSK). Más información...

Encabezado: #include <QSslPreSharedKeyAuthenticator>
CMake: find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
qmake: QT += network

Nota: Todas las funciones de esta clase son reentrantes.

Funciones públicas

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)

Descripción detallada

La clase QSslPreSharedKeyAuthenticator es utilizada por un socket SSL para proporcionar los datos de autenticación necesarios en un conjunto de cifrado de clave precompartida (PSK).

En un protocolo de enlace PSK, el cliente debe derivar una clave, que debe coincidir con la clave establecida en el servidor. El algoritmo exacto para derivar la clave depende de la aplicación; sin embargo, para este fin, el servidor puede enviar una pista de identidad al cliente. El cliente utiliza entonces esta pista, combinada con otra información (por ejemplo, una frase de contraseña), para construir la clave compartida.

El `QSslPreSharedKeyAuthenticator` proporciona a las aplicaciones cliente los medios para completar el protocolo de enlace PSK. La aplicación cliente debe conectar un slot a la señal ` QSslSocket::preSharedKeyAuthenticationRequired()`:

    connect(socket, &QSslSocket::preSharedKeyAuthenticationRequired,
            this, &AuthManager::handlePreSharedKeyAuthentication);

La señal transporta un objeto `QSslPreSharedKeyAuthenticator` que contiene la pista de identidad que el servidor envió al cliente, y que debe rellenarse con la identidad del cliente correspondiente y la clave derivada:

    void AuthManager::handlePreSharedKeyAuthentication(QSslPreSharedKeyAuthenticator *authenticator)
    {
        authenticator->setIdentity("My Qt App");

        const QByteArray key = deriveKey(authenticator->identityHint(), passphrase);
        authenticator->setPreSharedKey(key);
    }

Nota: Los conjuntos de cifradoPSK solo son compatibles cuando se utiliza OpenSSL 1.0.1 (o superior) como backend de SSL.

Nota: Actualmente,PSK solo es compatible con OpenSSL.

Véase también QSslSocket.

Documentación de las funciones miembro

QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator()

Crea un objeto QSslPreSharedKeyAuthenticator por defecto.

La pista de identidad, la identidad y la clave se inicializarán como matrices de bytes vacías; la longitud máxima tanto de la identidad como de la clave se inicializará en 0.

QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator(const QSslPreSharedKeyAuthenticator &authenticator)

Crea un objeto `QSslPreSharedKeyAuthenticator` como copia de ` authenticator`.

Véase también operator=().

[noexcept] QSslPreSharedKeyAuthenticator::~QSslPreSharedKeyAuthenticator()

Elimina el objeto « QSslPreSharedKeyAuthenticator ».

QByteArray QSslPreSharedKeyAuthenticator::identity() const

Devuelve la identidad del cliente PSK.

Véase también setIdentity().

QByteArray QSslPreSharedKeyAuthenticator::identityHint() const

Devuelve la indicación de identidad PSK tal y como la proporciona el servidor. La interpretación de esta indicación se deja en manos de la aplicación.

int QSslPreSharedKeyAuthenticator::maximumIdentityLength() const

Devuelve la longitud máxima, en bytes, de la identidad del cliente PSK.

Nota: es posible establecer una identidad cuya longitud sea superior a maximumIdentityLength(); en este caso, solo se enviarán al servidor los primeros maximumIdentityLength() bytes.

Véase también ` setIdentity()`.

int QSslPreSharedKeyAuthenticator::maximumPreSharedKeyLength() const

Devuelve la longitud máxima, en bytes, de la clave precompartida.

Nota: es posible establecer una clave cuya longitud sea mayor que maximumPreSharedKeyLength(); en este caso, solo se enviarán al servidor los primeros maximumPreSharedKeyLength() bytes.

Véase también ` setPreSharedKey()`.

QByteArray QSslPreSharedKeyAuthenticator::preSharedKey() const

Devuelve la clave precompartida.

Véase también setPreSharedKey().

void QSslPreSharedKeyAuthenticator::setIdentity(const QByteArray &identity)

Establece la identidad del cliente PSK (que se comunicará al servidor) en identity.

Nota: es posible establecer una identidad cuya longitud sea mayor que maximumIdentityLength(); en este caso, solo se enviarán realmente al servidor los primeros maximumIdentityLength() bytes.

Véanse también identity() y maximumIdentityLength().

void QSslPreSharedKeyAuthenticator::setPreSharedKey(const QByteArray &preSharedKey)

Establece la clave precompartida en preSharedKey.

Nota: es posible establecer una clave cuya longitud sea mayor que maximumPreSharedKeyLength(); en este caso, solo se enviarán realmente al servidor los primeros maximumPreSharedKeyLength() bytes.

Véanse también preSharedKey(), maximumPreSharedKeyLength() y QByteArray::fromHex().

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

Cambia este autenticador por other. Esta operación es muy rápida y nunca falla.

[noexcept] QSslPreSharedKeyAuthenticator &QSslPreSharedKeyAuthenticator::operator=(QSslPreSharedKeyAuthenticator &&authenticator)

Move asigna el objeto ` QSslPreSharedKeyAuthenticator ` ` authenticator ` a este objeto y devuelve una referencia a la instancia movida.

QSslPreSharedKeyAuthenticator &QSslPreSharedKeyAuthenticator::operator=(const QSslPreSharedKeyAuthenticator &authenticator)

Asigna el objeto « QSslPreSharedKeyAuthenticator » authenticator a este objeto y devuelve una referencia a la copia.

Elementos no miembros relacionados

bool operator!=(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)

Devuelve ` true ` si el objeto autenticador ` lhs ` no es igual a ` rhs`; en caso contrario, devuelve ` false `.

bool operator==(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)

Devuelve « true » si el objeto autenticador « lhs » es igual a « rhs »; en caso contrario, devuelve « false ».

Dos objetos autenticadores son iguales si y solo si tienen la misma pista de identidad, identidad, clave precompartida, longitud máxima de la identidad y longitud máxima de la clave precompartida.

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