Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 22 of file qsslkey.h.

Constructor & Destructor Documentation

◆ QSslKey() [1/6]

QSslKey::QSslKey ( )

Constructs a null key.

See also
isNull()

Definition at line 102 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 117 of file qsslkey_p.cpp.

References algorithm(), QSslKeyPrivate::backend, QSsl::Der, and encoded.

+ Here is the call graph for this function:

◆ 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 139 of file qsslkey_p.cpp.

References algorithm(), QSslKeyPrivate::backend, QSsl::Der, device, and encoded.

+ Here is the call graph for this function:

◆ 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 163 of file qsslkey_p.cpp.

References QSslKeyPrivate::backend.

◆ QSslKey() [5/6]

QSslKey::QSslKey ( const QSslKey & other)

Constructs an identical copy of other.

Definition at line 173 of file qsslkey_p.cpp.

◆ QSslKey() [6/6]

QSslKey::QSslKey ( QSslKey && other)
noexcept

Definition at line 177 of file qsslkey_p.cpp.

References d, other(), and qSwap().

+ Here is the call graph for this function:

◆ ~QSslKey()

QSslKey::~QSslKey ( )

Destroys the QSslKey object.

Definition at line 198 of file qsslkey_p.cpp.

Member Function Documentation

◆ algorithm()

QSsl::KeyAlgorithm QSslKey::algorithm ( ) const

Returns the key algorithm.

Definition at line 270 of file qsslkey_p.cpp.

References QSslKeyPrivate::backend, and QSsl::Opaque.

Referenced by QSslKey(), QSslKey(), operator==(), and toDer().

+ Here is the caller graph for this function:

◆ clear()

void QSslKey::clear ( )

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

See also
isNull()

Definition at line 240 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 324 of file qsslkey_p.cpp.

References QSslKeyPrivate::backend.

Referenced by operator==().

+ Here is the caller graph for this function:

◆ isNull()

bool QSslKey::isNull ( ) const

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

See also
clear()

Definition at line 227 of file qsslkey_p.cpp.

References QSslKeyPrivate::backend.

Referenced by QSslConfiguration::isNull(), operator==(), and toDer().

+ Here is the caller graph for this function:

◆ length()

int QSslKey::length ( ) const

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

Definition at line 248 of file qsslkey_p.cpp.

References QSslKeyPrivate::backend.

Referenced by operator==().

+ Here is the caller graph for this function:

◆ 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 57 of file qsslkey.h.

References operator==().

+ Here is the call graph for this function:

◆ 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 208 of file qsslkey_p.cpp.

References other().

+ Here is the call graph for this function:

◆ operator=() [2/2]

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

Definition at line 183 of file qsslkey_p.cpp.

References d, other(), and qSwap().

+ Here is the call graph for this function:

◆ operator==()

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

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

Definition at line 335 of file qsslkey_p.cpp.

References algorithm(), handle(), isNull(), length(), QSsl::Opaque, other(), toDer(), and type().

+ Here is the call graph for this function:

◆ swap()

void QSslKey::swap ( QSslKey & other)
inlinenoexcept
Since
5.0

Swaps this ssl key with other. This function is very fast and never fails.

Definition at line 41 of file qsslkey.h.

References d, and other().

+ Here is the call graph for this function:

◆ 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 284 of file qsslkey_p.cpp.

References algorithm(), QSslKeyPrivate::backend, isNull(), QSsl::Opaque, QSsl::PrivateKey, toPem(), and type().

Referenced by operator==().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 305 of file qsslkey_p.cpp.

References QSslKeyPrivate::backend.

Referenced by toDer().

+ Here is the caller graph for this function:

◆ type()

QSsl::KeyType QSslKey::type ( ) const

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

Definition at line 259 of file qsslkey_p.cpp.

References QSslKeyPrivate::backend, and QSsl::PublicKey.

Referenced by operator==(), and toDer().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QTlsBackend

friend class QTlsBackend
friend

Definition at line 61 of file qsslkey.h.


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