QSslKey Class
The QSslKey class holds a public or private key. More…
| Header | #include <QSslKey> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Network) |
| Module | Nt Network C++ Classes |
List of all members, including inherited members
Public Functions
| QSslKey() | |
| QSslKey(const QByteArray &encoded, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat format = QSsl::Pem, QSsl::KeyType type = QSsl::PrivateKey, const QByteArray &passPhrase = QByteArray()) | |
| QSslKey(QIODevice *device, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat format = QSsl::Pem, QSsl::KeyType type = QSsl::PrivateKey, const QByteArray &passPhrase = QByteArray()) | |
| bool | isNull() const |
| void | clear() |
| int | length() const |
| QSsl::KeyType | type() const |
| QSsl::KeyAlgorithm | algorithm() const |
| QByteArray | toPem() const |
| QByteArray | toDer() const |
Detailed Description
QFile file("server.key");
file.open(QIODevice::ReadOnly);
QSslKey key(file.readAll(), QSsl::Ec);
See also QSslCertificate and QSslConfiguration.
Differences from Qt
toPem() and toDer() have no pass phrase argument, and the key is held unencrypted in memory after it is loaded. There is no handle(). On Zephyr, with Mbed TLS, a private key is held in the form of its algorithm (PKCS #1 for RSA, SEC 1 for an elliptic curve) and not as PKCS #8, so toDer() and toPem() give that form, and only RSA and elliptic curve keys are read.
Member Function Documentation
QSslKey::QSslKey()
Constructs a null key.
QSslKey::QSslKey(const QByteArray &encoded, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat format = QSsl::Pem, QSsl::KeyType type = QSsl::PrivateKey, const QByteArray &passPhrase = QByteArray())
Constructs a key by parsing encoded, which is in format and holds a key of the given type. passPhrase decrypts a protected key. The key is null if parsing fails, or if the key is not an algorithm key.
See also isNull().
QSslKey::QSslKey(QIODevice *device, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat format = QSsl::Pem, QSsl::KeyType type = QSsl::PrivateKey, const QByteArray &passPhrase = QByteArray())
This is an overloaded function.
Constructs a key from the contents of device, using algorithm, format, type and passPhrase as above.
QSsl::KeyAlgorithm QSslKey::algorithm() const
Returns the key's algorithm.
void QSslKey::clear()
Makes the key null.
bool QSslKey::isNull() const
Returns true if no key is held.
int QSslKey::length() const
Returns the key's length in bits, or -1 if the key is null.
QByteArray QSslKey::toDer() const
Returns the key in DER format, unencrypted.
See also toPem().
QByteArray QSslKey::toPem() const
Returns the key in PEM format, unencrypted.
See also toDer().
QSsl::KeyType QSslKey::type() const
Returns whether this is a private or public key.