QOpcUaKeyPair Class

QOpcUaKeyPair handles private and public key pairs. More...

Header: #include <QOpcUaKeyPair>
qmake: QT += opcua
Since: Qt 5.14
Inherits: QObject

This class was introduced in Qt 5.14.

Public Types

enum class Cipher { Aes128Cbc, Unencrypted }
enum class KeyType { Rsa, Empty, Unknown }
enum class RsaKeyStrength { Bits1024, Bits2048, Bits4096 }

Public Functions

QOpcUaKeyPair(QObject *parent = nullptr)
virtual ~QOpcUaKeyPair()
void generateRsaKey(QOpcUaKeyPair::RsaKeyStrength strength)
bool hasPrivateKey() const
bool loadFromPemData(const QByteArray &data)
QByteArray privateKeyToByteArray(QOpcUaKeyPair::Cipher cipher, const QString &password) const
QByteArray publicKeyToByteArray() const
QOpcUaKeyPair::KeyType type() const

Detailed Description

This class is currently available as a Technology Preview, and therefore the API and functionality provided by the class may be subject to change at any time without prior notice.

It can generate, load and store keys for asymmetric encryption. Instances of this class have to be passed to functions which need a key.

Member Type Documentation

enum class QOpcUaKeyPair::Cipher

Ciphers for encryption of private keys.

ConstantValueDescription
QOpcUaKeyPair::Cipher::Aes128Cbc0Encrypting AES128 with CBC
QOpcUaKeyPair::Cipher::Unencrypted1The Key will not be encrypted.

enum class QOpcUaKeyPair::KeyType

This enum type specifies the type of a key.

ConstantValueDescription
QOpcUaKeyPair::KeyType::Rsa0An RSA key
QOpcUaKeyPair::KeyType::Empty1No key is available.
QOpcUaKeyPair::KeyType::Unknown2The type of key is not handled.

enum class QOpcUaKeyPair::RsaKeyStrength

This enum type specifies the strength of a RSA key.

ConstantValueDescription
QOpcUaKeyPair::RsaKeyStrength::Bits10241024A key strength of 1024 bits.
QOpcUaKeyPair::RsaKeyStrength::Bits20482048A key strength of 2048 bits.
QOpcUaKeyPair::RsaKeyStrength::Bits40964096A key strength of 4096 bits.

Member Function Documentation

QOpcUaKeyPair::QOpcUaKeyPair(QObject *parent = nullptr)

Creates a new empty key pair.

[virtual] QOpcUaKeyPair::~QOpcUaKeyPair()

Destroys the key pair.

void QOpcUaKeyPair::generateRsaKey(QOpcUaKeyPair::RsaKeyStrength strength)

Generates a new asymmetric RSA key pair.

The length of the key can be specified by the strength parameter.

bool QOpcUaKeyPair::hasPrivateKey() const

Returns true if the current key contains a private key, otherwise false.

bool QOpcUaKeyPair::loadFromPemData(const QByteArray &data)

Loads a key from PEM encoded data in data. Returns true on success and false otherwise.

It detects from the PEM header if the data contains a private or public key. Loading encrypted keys is possible by connecting a function to the signal passphraseNeeded for provision of the passphrase.

QByteArray QOpcUaKeyPair::privateKeyToByteArray(QOpcUaKeyPair::Cipher cipher, const QString &password) const

Returns the PEM encoded private key. In case there is no private key, an empty byte array is returned.

The encryption of the key has to be specified using the parameters cipher and password. In order to store the key unencrypted the cipher Cipher::Unencrypted has to be used.

QByteArray QOpcUaKeyPair::publicKeyToByteArray() const

Loads a key from PEM encoded data in data. Returns true on success and false otherwise.

It detects from the PEM header if the data contains a private or public key. Loading encrypted keys is possible by connecting a function to the signal passphraseNeeded for provision of the passphrase.

QOpcUaKeyPair::KeyType QOpcUaKeyPair::type() const

Returns the type of the current key.

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