QCA::PublicKey

Search for usage in LXR

#include <QtCrypto>

Inheritance diagram for QCA::PublicKey:

Public Member Functions

 PublicKey ()
 
 PublicKey (const PrivateKey &k)
 
 PublicKey (const PublicKey &from)
 
 PublicKey (const QString &fileName)
 
bool canDecrypt () const
 
bool canEncrypt () const
 
bool canVerify () const
 
bool decrypt (const SecureArray &in, SecureArray *out, EncryptionAlgorithm alg)
 
SecureArray encrypt (const SecureArray &a, EncryptionAlgorithm alg)
 
int maximumEncryptSize (EncryptionAlgorithm alg) const
 
PublicKeyoperator= (const PublicKey &from)
 
void startVerify (SignatureAlgorithm alg, SignatureFormat format=DefaultFormat)
 
QByteArray toDER () const
 
DHPublicKey toDH () const
 
DSAPublicKey toDSA () const
 
QString toPEM () const
 
bool toPEMFile (const QString &fileName) const
 
RSAPublicKey toRSA () const
 
void update (const MemoryRegion &a)
 
bool validSignature (const QByteArray &sig)
 
bool verifyMessage (const MemoryRegion &a, const QByteArray &sig, SignatureAlgorithm alg, SignatureFormat format=DefaultFormat)
 
- 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 (const QString &type, const QString &provider)
 
void change (Provider::Context *c)
 
Provider::Contextcontext ()
 
const Provider::Contextcontext () const
 
Algorithmoperator= (const Algorithm &from)
 
Providerprovider () const
 
Provider::ContexttakeContext ()
 
QString type () const
 

Static Public Member Functions

static PublicKey fromDER (const QByteArray &a, ConvertResult *result=nullptr, const QString &provider=QString())
 
static PublicKey fromPEM (const QString &s, ConvertResult *result=nullptr, const QString &provider=QString())
 
static PublicKey fromPEMFile (const QString &fileName, ConvertResult *result=nullptr, 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

 PublicKey (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 public key.

Examples
rsatest.cpp.

Definition at line 528 of file qca_publickey.h.

Constructor & Destructor Documentation

◆ PublicKey() [1/5]

QCA::PublicKey::PublicKey ( )

Create an empty (null) public key.

◆ PublicKey() [2/5]

QCA::PublicKey::PublicKey ( const PrivateKey & k)

Create a public key based on a specified private key.

Parameters
kthe private key to extract the public key parts from

◆ PublicKey() [3/5]

QCA::PublicKey::PublicKey ( const QString & fileName)

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

Parameters
fileNamethe name of the file containing the public key
See also
fromPEMFile for an alternative method

◆ PublicKey() [4/5]

QCA::PublicKey::PublicKey ( const PublicKey & from)

Copy constructor.

Parameters
fromthe PublicKey to copy from

◆ PublicKey() [5/5]

QCA::PublicKey::PublicKey ( const QString & type,
const QString & provider )
protected

Create a new key of a specified type.

Parameters
typethe type of key to create
providerthe provider to use, if required

Member Function Documentation

◆ canDecrypt()

bool QCA::PublicKey::canDecrypt ( ) const

Test if this key can be used for decryption.

Returns
true if the key can be used for decryption

◆ canEncrypt()

bool QCA::PublicKey::canEncrypt ( ) const

Test if this key can be used for encryption.

Returns
true if the key can be used for encryption
Examples
rsatest.cpp.

◆ canVerify()

bool QCA::PublicKey::canVerify ( ) const

Test if the key can be used for verifying signatures.

Returns
true of the key can be used for verification
Examples
rsatest.cpp.

◆ decrypt()

bool QCA::PublicKey::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.

◆ encrypt()

SecureArray QCA::PublicKey::encrypt ( const SecureArray & a,
EncryptionAlgorithm alg )

Encrypt a message using a specified algorithm.

Parameters
athe message to encrypt
algthe algorithm to use
Examples
rsatest.cpp.

◆ fromDER()

static PublicKey QCA::PublicKey::fromDER ( const QByteArray & a,
ConvertResult * result = nullptr,
const QString & provider = QString() )
static

Import a key in Distinguished Encoding Rules (DER) format.

This function takes a binary array, which is assumed to contain a public key in DER encoding, and returns the key. Unless you don't care whether the import succeeded, you should test the result, as shown below.

QCA::ConvertResult conversionResult;
QCA::PublicKey publicKey = QCA::PublicKey::fromDER(keyArray, &conversionResult);
if (! QCA::ConvertGood == conversionResult)
{
std::cout << "Public key read failed" << std::endl;
}
Generic public key.
static PublicKey fromDER(const QByteArray &a, ConvertResult *result=nullptr, const QString &provider=QString())
Import a key in Distinguished Encoding Rules (DER) format.
ConvertResult
Return value from a format conversion.
@ ConvertGood
Conversion succeeded, results should be valid.
Parameters
athe array containing a DER encoded key
resultpointer to a variable, which returns whether the conversion succeeded (ConvertGood) or not
providerthe name of the provider to use for the import.

◆ fromPEM()

static PublicKey QCA::PublicKey::fromPEM ( const QString & s,
ConvertResult * result = nullptr,
const QString & provider = QString() )
static

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

This function takes a string, which is assumed to contain a public key in PEM encoding, and returns that key. Unless you don't care whether the import succeeded, you should test the result, as shown below.

QCA::ConvertResult conversionResult;
QCA::PublicKey publicKey = QCA::PublicKey::fromPEM(keyAsString, &conversionResult);
if (! QCA::ConvertGood == conversionResult)
{
std::cout << "Public key read failed" << std::endl;
}
static PublicKey fromPEM(const QString &s, ConvertResult *result=nullptr, const QString &provider=QString())
Import a key in Privacy Enhanced Mail (PEM) format.
Parameters
sthe string containing a PEM encoded key
resultpointer to a variable, which returns whether the conversion succeeded (ConvertGood) or not
providerthe name of the provider to use for the import.
See also
toPEM, which provides an inverse of fromPEM()
fromPEMFile, which provides an import direct from a file.

◆ fromPEMFile()

static PublicKey QCA::PublicKey::fromPEMFile ( const QString & fileName,
ConvertResult * result = nullptr,
const QString & provider = QString() )
static

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

This function takes the name of a file, which is assumed to contain a public key in PEM encoding, and returns that key. Unless you don't care whether the import succeeded, you should test the result, as shown below.

QCA::ConvertResult conversionResult;
QCA::PublicKey publicKey = QCA::PublicKey::fromPEMFile(fileName, &conversionResult);
if (! QCA::ConvertGood == conversionResult)
{
std::cout << "Public key read failed" << std::endl;
}
static PublicKey fromPEMFile(const QString &fileName, ConvertResult *result=nullptr, const QString &provider=QString())
Import a key in Privacy Enhanced Mail (PEM) format from a file.
Parameters
fileNamea string containing the name of the file
resultpointer to a variable, which returns whether the conversion succeeded (ConvertGood) or not
providerthe name of the provider to use for the import.
See also
toPEMFile, which provides an inverse of fromPEMFile()
fromPEM, which provides an import from a string
Note
there is also a constructor form that can import from a file

◆ maximumEncryptSize()

int QCA::PublicKey::maximumEncryptSize ( EncryptionAlgorithm alg) const

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

Parameters
algthe algorithm to check

◆ operator=()

PublicKey & QCA::PublicKey::operator= ( const PublicKey & from)

Assignment operator.

Parameters
fromthe PublicKey to copy from

◆ startVerify()

void QCA::PublicKey::startVerify ( SignatureAlgorithm alg,
SignatureFormat format = DefaultFormat )

Initialise the signature verification process.

Parameters
algthe algorithm to use for signing
formatthe specific format to use, for DSA
Examples
rsatest.cpp.

◆ toDER()

QByteArray QCA::PublicKey::toDER ( ) const

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

◆ toDH()

DHPublicKey QCA::PublicKey::toDH ( ) const

Convenience method to convert this key to a DHPublicKey.

Note that if the key is not an DH key (eg it is DSA or RSA), then this will produce a null key.

◆ toDSA()

DSAPublicKey QCA::PublicKey::toDSA ( ) const

Convenience method to convert this key to a DSAPublicKey.

Note that if the key is not an DSA key (eg it is RSA or DH), then this will produce a null key.

◆ toPEM()

QString QCA::PublicKey::toPEM ( ) const

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

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 PublicKey

◆ toPEMFile()

bool QCA::PublicKey::toPEMFile ( const QString & fileName) const

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

Parameters
fileNamethe name (and path, if necessary) of the file to save the PEM encoded key to.
See also
toPEM for a version that exports to a QString, which may be useful if you need to do more sophisticated handling
fromPEMFile provides an inverse of toPEMFile, reading a PEM encoded key from a file

◆ toRSA()

RSAPublicKey QCA::PublicKey::toRSA ( ) const

Convenience method to convert this key to an RSAPublicKey.

Note that if the key is not an RSA key (eg it is DSA or DH), then this will produce a null key.

◆ update()

void QCA::PublicKey::update ( const MemoryRegion & a)

Update the signature verification process with more data.

Parameters
athe array containing the data that should be added to the signature
Examples
rsatest.cpp.

◆ validSignature()

bool QCA::PublicKey::validSignature ( const QByteArray & sig)

Check the signature is valid for the message.

The process to check that a signature is correct is shown below:

// note that pubkey is a PublicKey
if( pubkey.canVerify() )
{
pubkey.startVerify( QCA::EMSA3_MD5 );
pubkey.update( theMessage ); // might be called multiple times
if ( pubkey.validSignature( theSignature ) )
{
// then signature is valid
}
else
{
// then signature is invalid
}
}
@ EMSA3_MD5
MD5, with EMSA3 (ie PKCS#1 Version 1.5) encoding (this is the usual RSA algorithm)
Parameters
sigthe signature to check
Returns
true if the signature is correct
Examples
rsatest.cpp.

◆ verifyMessage()

bool QCA::PublicKey::verifyMessage ( const MemoryRegion & a,
const QByteArray & sig,
SignatureAlgorithm alg,
SignatureFormat format = DefaultFormat )

Single step message verification.

If you have the whole message to be verified, then this offers a more convenient approach to verification.

Parameters
athe message to check the signature on
sigthe signature to be checked
algthe algorithm to use
formatthe signature format to use, for DSA
Returns
true if the signature is valid for the message
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-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:48:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.