Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QSslKey Class Reference

The QSslKey class provides an interface for private and public keys. More...

#include <qsslkey.h>

Collaboration diagram for QSslKey:

Public Member Functions

 QSslKey ()
 Constructs a null key.
 QSslKey (const QByteArray &encoded, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat format=QSsl::Pem, QSsl::KeyType type=QSsl::PrivateKey, const QByteArray &passPhrase=QByteArray())
 Constructs a QSslKey by decoding the string in the byte array encoded using a specified algorithm and encoding format.
 QSslKey (QIODevice *device, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat format=QSsl::Pem, QSsl::KeyType type=QSsl::PrivateKey, const QByteArray &passPhrase=QByteArray())
 Constructs a QSslKey by reading and decoding data from a device using a specified algorithm and encoding format.
 QSslKey (Qt::HANDLE handle, QSsl::KeyType type=QSsl::PrivateKey)
 QSslKey (const QSslKey &other)
 Constructs an identical copy of other.
 QSslKey (QSslKey &&other) noexcept
QSslKeyoperator= (QSslKey &&other) noexcept
QSslKeyoperator= (const QSslKey &other)
 Copies the contents of other into this key, making the two keys identical.
 ~QSslKey ()
 Destroys the QSslKey object.
void swap (QSslKey &other) noexcept
bool isNull () const
 Returns true if this is a null key; otherwise false.
void clear ()
 Clears the contents of this key, making it a null key.
int length () const
 Returns the length of the key in bits, or -1 if the key is null.
QSsl::KeyType type () const
 Returns the type of the key (i.e., PublicKey or PrivateKey).
QSsl::KeyAlgorithm algorithm () const
 Returns the key algorithm.
QByteArray toPem (const QByteArray &passPhrase=QByteArray()) const
 Returns the key in PEM encoding.
QByteArray toDer (const QByteArray &passPhrase=QByteArray()) const
 Returns the key in DER encoding.
Qt::HANDLE handle () const
 Returns a pointer to the native key handle, if there is one, else \nullptr.
bool operator== (const QSslKey &key) const
 Returns true if this key is equal to other; otherwise returns false.
bool operator!= (const QSslKey &key) const
 Returns true if this key is not equal to key other; otherwise returns false.

Friends

class QTlsBackend

Detailed Description

The QSslKey class provides an interface for private and public keys.

Since
4.3

\reentrant

\inmodule QtNetwork

QSslKey provides a simple API for managing keys.

See also
QSslSocket, QSslCertificate, QSslCipher

Definition at line 23 of file qsslkey.h.

Constructor & Destructor Documentation

◆ QSslKey() [1/6]

QSslKey::QSslKey ( )

Constructs a null key.

See also
isNull()

Definition at line 103 of file qsslkey_p.cpp.

◆ QSslKey() [2/6]

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

Constructs a QSslKey by decoding the string in the byte array encoded using a specified algorithm and encoding format.

type specifies whether the key is public or private.

If the key is encrypted then passPhrase is used to decrypt it.

After construction, use isNull() to check if encoded contained a valid key.

Definition at line 118 of file qsslkey_p.cpp.

◆ QSslKey() [3/6]

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

Constructs a QSslKey by reading and decoding data from a device using a specified algorithm and encoding format.

type specifies whether the key is public or private.

If the key is encrypted then passPhrase is used to decrypt it.

After construction, use isNull() to check if device provided a valid key.

Definition at line 140 of file qsslkey_p.cpp.

◆ QSslKey() [4/6]

QSslKey::QSslKey ( Qt::HANDLE handle,
QSsl::KeyType type = QSsl::PrivateKey )
explicit
Since
5.0 Constructs a QSslKey from a valid native key handle. type specifies whether the key is public or private.

QSslKey will take ownership for this key and you must not free the key using the native library.

Definition at line 164 of file qsslkey_p.cpp.

◆ QSslKey() [5/6]

QSslKey::QSslKey ( const QSslKey & other)

Constructs an identical copy of other.

Definition at line 174 of file qsslkey_p.cpp.

◆ QSslKey() [6/6]

QSslKey::QSslKey ( QSslKey && other)
noexcept

Definition at line 178 of file qsslkey_p.cpp.

◆ ~QSslKey()

QSslKey::~QSslKey ( )

Destroys the QSslKey object.

Definition at line 199 of file qsslkey_p.cpp.

Member Function Documentation

◆ algorithm()

QSsl::KeyAlgorithm QSslKey::algorithm ( ) const

Returns the key algorithm.

Definition at line 269 of file qsslkey_p.cpp.

◆ clear()

void QSslKey::clear ( )

Clears the contents of this key, making it a null key.

See also
isNull()

Definition at line 239 of file qsslkey_p.cpp.

◆ handle()

Qt::HANDLE QSslKey::handle ( ) const

Returns a pointer to the native key handle, if there is one, else \nullptr.

You can use this handle together with the native API to access extended information about the key.

Warning
Use of this function has a high probability of being non-portable, and its return value may vary across platforms, and between minor Qt releases.

Definition at line 323 of file qsslkey_p.cpp.

◆ isNull()

bool QSslKey::isNull ( ) const

Returns true if this is a null key; otherwise false.

See also
clear()

Definition at line 226 of file qsslkey_p.cpp.

◆ length()

int QSslKey::length ( ) const

Returns the length of the key in bits, or -1 if the key is null.

Definition at line 247 of file qsslkey_p.cpp.

◆ operator!=()

bool QSslKey::operator!= ( const QSslKey & key) const
inline

Returns true if this key is not equal to key other; otherwise returns false.

Definition at line 58 of file qsslkey.h.

◆ operator=() [1/2]

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

Copies the contents of other into this key, making the two keys identical.

Returns a reference to this QSslKey.

Definition at line 209 of file qsslkey_p.cpp.

◆ operator=() [2/2]

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

Definition at line 184 of file qsslkey_p.cpp.

◆ operator==()

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

Returns true if this key is equal to other; otherwise returns false.

Definition at line 334 of file qsslkey_p.cpp.

◆ swap()

void QSslKey::swap ( QSslKey & other)
inlinenoexcept
Since
5.0 \memberswap{ssl key}

Definition at line 42 of file qsslkey.h.

◆ toDer()

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

Returns the key in DER encoding.

The passPhrase argument should be omitted as DER cannot be encrypted. It will be removed in a future version of Qt.

Definition at line 283 of file qsslkey_p.cpp.

◆ toPem()

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

Returns the key in PEM encoding.

The result is encrypted with passPhrase if the key is a private key and passPhrase is non-empty.

Definition at line 304 of file qsslkey_p.cpp.

◆ type()

QSsl::KeyType QSslKey::type ( ) const

Returns the type of the key (i.e., PublicKey or PrivateKey).

Definition at line 258 of file qsslkey_p.cpp.

◆ QTlsBackend

friend class QTlsBackend
friend

Definition at line 62 of file qsslkey.h.


The documentation for this class was generated from the following files: