QCA::PrivateKey

#include <QtCrypto>

Inheritance diagram for QCA::PrivateKey:

Public Member Functions

 PrivateKey ()
 
 PrivateKey (const QString &fileName, const SecureArray &passphrase=SecureArray())
 
 PrivateKey (const PrivateKey &from)
 
bool canDecrypt () const
 
bool canEncrypt () const
 
bool canSign () const
 
bool decrypt (const SecureArray &in, SecureArray *out, EncryptionAlgorithm alg)
 
SymmetricKey deriveKey (const PublicKey &theirs)
 
SecureArray encrypt (const SecureArray &a, EncryptionAlgorithm alg)
 
int maximumEncryptSize (EncryptionAlgorithm alg) const
 
PrivateKeyoperator= (const PrivateKey &from)
 
QByteArray signature ()
 
QByteArray signMessage (const MemoryRegion &a, SignatureAlgorithm alg, SignatureFormat format=DefaultFormat)
 
void startSign (SignatureAlgorithm alg, SignatureFormat format=DefaultFormat)
 
SecureArray toDER (const SecureArray &passphrase=SecureArray(), PBEAlgorithm pbe=PBEDefault) const
 
DHPrivateKey toDH () const
 
DSAPrivateKey toDSA () const
 
QString toPEM (const SecureArray &passphrase=SecureArray(), PBEAlgorithm pbe=PBEDefault) const
 
bool toPEMFile (const QString &fileName, const SecureArray &passphrase=SecureArray(), PBEAlgorithm pbe=PBEDefault) const
 
RSAPrivateKey toRSA () const
 
void update (const MemoryRegion &a)
 
- Public Member Functions inherited from QCA::PKey
 PKey ()
 
 PKey (const PKey &from)
 
int bitSize () const
 
bool canExport () const
 
bool canKeyAgree () const
 
bool isDH () const
 
bool isDSA () const
 
bool isNull () const
 
bool isPrivate () const
 
bool isPublic () const
 
bool isRSA () const
 
bool operator!= (const PKey &a) const
 
PKeyoperator= (const PKey &from)
 
bool operator== (const PKey &a) const
 
PrivateKey toPrivateKey () const
 
PublicKey toPublicKey () const
 
Type type () const
 
- Public Member Functions inherited from QCA::Algorithm
 Algorithm (const Algorithm &from)
 
void change (Provider::Context *c)
 
void change (const QString &type, const QString &provider)
 
Provider::Contextcontext ()
 
const Provider::Contextcontext () const
 
Algorithmoperator= (const Algorithm &from)
 
Providerprovider () const
 
Provider::ContexttakeContext ()
 
QString type () const
 

Static Public Member Functions

static PrivateKey fromDER (const SecureArray &a, const SecureArray &passphrase=SecureArray(), ConvertResult *result=nullptr, const QString &provider=QString())
 
static PrivateKey fromPEM (const QString &s, const SecureArray &passphrase=SecureArray(), ConvertResult *result=nullptr, const QString &provider=QString())
 
static PrivateKey fromPEMFile (const QString &fileName, const SecureArray &passphrase=SecureArray(), ConvertResult *result=nullptr, const QString &provider=QString())
 
static QList< PBEAlgorithmsupportedPBEAlgorithms (const QString &provider=QString())
 
- Static Public Member Functions inherited from QCA::PKey
static QList< TypesupportedIOTypes (const QString &provider=QString())
 
static QList< TypesupportedTypes (const QString &provider=QString())
 

Protected Member Functions

 PrivateKey (const QString &type, const QString &provider)
 
- Protected Member Functions inherited from QCA::PKey
 PKey (const QString &type, const QString &provider)
 
void set (const PKey &k)
 
DHPrivateKey toDHPrivateKey () const
 
DHPublicKey toDHPublicKey () const
 
DSAPrivateKey toDSAPrivateKey () const
 
DSAPublicKey toDSAPublicKey () const
 
RSAPrivateKey toRSAPrivateKey () const
 
RSAPublicKey toRSAPublicKey () const
 
- Protected Member Functions inherited from QCA::Algorithm
 Algorithm ()
 
 Algorithm (const QString &type, const QString &provider)
 

Additional Inherited Members

- Public Types inherited from QCA::PKey
enum  Type { RSA, DSA, DH }
 

Detailed Description

Generic private key.

Examples:
keyloader.cpp, publickeyexample.cpp, rsatest.cpp, and sslservtest.cpp.

Definition at line 832 of file qca_publickey.h.

Constructor & Destructor Documentation

QCA::PrivateKey::PrivateKey ( )

Create an empty private key.

QCA::PrivateKey::PrivateKey ( const QString fileName,
const SecureArray passphrase = SecureArray() 
)
explicit

Import a private key from a PEM representation in a file.

Parameters
fileNamethe name of the file containing the private key
passphrasethe pass phrase for the private key
See also
fromPEMFile for an alternative method
Note
This synchronous operation may require event handling, and so it must not be called from the same thread as an EventHandler.
QCA::PrivateKey::PrivateKey ( const PrivateKey from)

Copy constructor.

Parameters
fromthe PrivateKey to copy from
QCA::PrivateKey::PrivateKey ( const QString type,
const QString provider 
)
protected

Create a new private key.

Parameters
typethe type of key to create
providerthe provider to use, if a specific provider is required.

Member Function Documentation

bool QCA::PrivateKey::canDecrypt ( ) const

Test if this key can be used for decryption.

Returns
true if the key can be used for decryption
Examples:
publickeyexample.cpp.
bool QCA::PrivateKey::canEncrypt ( ) const

Test if this key can be used for encryption.

Returns
true if the key can be used for encryption
bool QCA::PrivateKey::canSign ( ) const

Test if this key can be used for signing.

Returns
true if the key can be used to make a signature
Examples:
rsatest.cpp.
bool QCA::PrivateKey::decrypt ( const SecureArray in,
SecureArray out,
EncryptionAlgorithm  alg 
)

Decrypt the message.

Parameters
inthe cipher (encrypted) data
outthe plain text data
algthe algorithm to use
Note
This synchronous operation may require event handling, and so it must not be called from the same thread as an EventHandler.
Examples:
publickeyexample.cpp, and rsatest.cpp.
SymmetricKey QCA::PrivateKey::deriveKey ( const PublicKey theirs)

Derive a shared secret key from a public key.

Parameters
theirsthe public key to derive from
SecureArray QCA::PrivateKey::encrypt ( const SecureArray a,
EncryptionAlgorithm  alg 
)

Encrypt a message using a specified algorithm.

Parameters
athe message to encrypt
algthe algorithm to use
static PrivateKey QCA::PrivateKey::fromDER ( const SecureArray a,
const SecureArray passphrase = SecureArray(),
ConvertResult result = nullptr,
const QString provider = QString() 
)
static

Import the key from Distinguished Encoding Rules (DER) format.

Parameters
athe array containing the DER representation of the key
passphrasethe pass phrase that is used to protect the key
resulta pointer to a ConvertResult, that if specified, will be set to reflect the result of the import
providerthe provider to use, if a particular provider is required
See also
toDER provides an inverse of fromDER, exporting the key to an array
QCA::KeyLoader for an asynchronous loader approach.
Note
This synchronous operation may require event handling, and so it must not be called from the same thread as an EventHandler.
static PrivateKey QCA::PrivateKey::fromPEM ( const QString s,
const SecureArray passphrase = SecureArray(),
ConvertResult result = nullptr,
const QString provider = QString() 
)
static

Import the key from Privacy Enhanced Mail (PEM) format.

Parameters
sthe string containing the PEM representation of the key
passphrasethe pass phrase that is used to protect the key
resulta pointer to a ConvertResult, that if specified, will be set to reflect the result of the import
providerthe provider to use, if a particular provider is required
See also
toPEM provides an inverse of fromPEM, exporting the key to a string in PEM encoding.
QCA::KeyLoader for an asynchronous loader approach.
Note
This synchronous operation may require event handling, and so it must not be called from the same thread as an EventHandler.
Examples:
sslservtest.cpp.
static PrivateKey QCA::PrivateKey::fromPEMFile ( const QString fileName,
const SecureArray passphrase = SecureArray(),
ConvertResult result = nullptr,
const QString provider = QString() 
)
static

Import the key in Privacy Enhanced Mail (PEM) format from a file.

Parameters
fileNamethe name (and path, if required) of the file containing the PEM representation of the key
passphrasethe pass phrase that is used to protect the key
resulta pointer to a ConvertResult, that if specified, will be set to reflect the result of the import
providerthe provider to use, if a particular provider is required
See also
toPEMFile provides an inverse of fromPEMFile
fromPEM which allows import from a string
QCA::KeyLoader for an asynchronous loader approach.
Note
there is also a constructor form, that allows you to create the key directly
This synchronous operation may require event handling, and so it must not be called from the same thread as an EventHandler.
Examples:
publickeyexample.cpp, and rsatest.cpp.
int QCA::PrivateKey::maximumEncryptSize ( EncryptionAlgorithm  alg) const

The maximum message size that can be encrypted with a specified algorithm.

Parameters
algthe algorithm to check
PrivateKey& QCA::PrivateKey::operator= ( const PrivateKey from)

Assignment operator.

Parameters
fromthe PrivateKey to copy from
QByteArray QCA::PrivateKey::signature ( )

The resulting signature.

Note
This synchronous operation may require event handling, and so it must not be called from the same thread as an EventHandler.
Examples:
rsatest.cpp.
QByteArray QCA::PrivateKey::signMessage ( const MemoryRegion a,
SignatureAlgorithm  alg,
SignatureFormat  format = DefaultFormat 
)

One step signature process.

Parameters
athe message to sign
algthe algorithm to use for the signature
formatthe signature format to use, for DSA
Returns
the signature
Note
This synchronous operation may require event handling, and so it must not be called from the same thread as an EventHandler.
void QCA::PrivateKey::startSign ( SignatureAlgorithm  alg,
SignatureFormat  format = DefaultFormat 
)

Initialise the message signature process.

Parameters
algthe algorithm to use for the message signature process
formatthe signature format to use, for DSA
Note
This synchronous operation may require event handling, and so it must not be called from the same thread as an EventHandler.
Examples:
rsatest.cpp.
static QList<PBEAlgorithm> QCA::PrivateKey::supportedPBEAlgorithms ( const QString provider = QString())
static

List the supported Password Based Encryption Algorithms that can be used to protect the key.

Parameters
providerthe provider to use, if a particular provider is required
SecureArray QCA::PrivateKey::toDER ( const SecureArray passphrase = SecureArray(),
PBEAlgorithm  pbe = PBEDefault 
) const

Export the key in Distinguished Encoding Rules (DER) format.

Parameters
passphrasethe pass phrase to use to protect the key
pbethe symmetric encryption algorithm to use to protect the key
See also
fromDER provides an inverse of toDER, converting the DER encoded key back to a PrivateKey
DHPrivateKey QCA::PrivateKey::toDH ( ) const

Interpret / convert the key to a Diffie-Hellman key.

DSAPrivateKey QCA::PrivateKey::toDSA ( ) const

Interpret / convert the key to a DSA key.

QString QCA::PrivateKey::toPEM ( const SecureArray passphrase = SecureArray(),
PBEAlgorithm  pbe = PBEDefault 
) const

Export the key in Privacy Enhanced Mail (PEM) format.

Parameters
passphrasethe pass phrase to use to protect the key
pbethe symmetric encryption algorithm to use to protect the key
See also
toPEMFile provides a convenient way to save the PEM encoded key to a file
fromPEM provides an inverse of toPEM, converting the PEM encoded key back to a PrivateKey
bool QCA::PrivateKey::toPEMFile ( const QString fileName,
const SecureArray passphrase = SecureArray(),
PBEAlgorithm  pbe = PBEDefault 
) const

Export the key in Privacy Enhanced Mail (PEM) format to a file.

Parameters
fileNamethe name (and path, if required) that the key should be exported to.
passphrasethe pass phrase to use to protect the key
pbethe symmetric encryption algorithm to use to protect the key
Returns
true if the export succeeds
See also
toPEM provides a convenient way to save the PEM encoded key to a file
fromPEM provides an inverse of toPEM, converting the PEM encoded key back to a PrivateKey
Examples:
rsatest.cpp.
RSAPrivateKey QCA::PrivateKey::toRSA ( ) const

Interpret / convert the key to an RSA key.

void QCA::PrivateKey::update ( const MemoryRegion a)

Update the signature process.

Parameters
athe message to use to update the signature
Note
This synchronous operation may require event handling, and so it must not be called from the same thread as an EventHandler.
Examples:
rsatest.cpp.

The documentation for this class was generated from the following file:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Oct 30 2020 23:07:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.