#include <QtCrypto>
Inheritance diagram for QCA::PublicKey:


Public Member Functions | |
| bool | canEncrypt () const |
| bool | canVerify () const |
| SecureArray | encrypt (const SecureArray &a, EncryptionAlgorithm alg) |
| int | maximumEncryptSize (EncryptionAlgorithm alg) const |
| PublicKey & | operator= (const PublicKey &from) |
| PublicKey (const PublicKey &from) | |
| PublicKey (const QString &fileName) | |
| PublicKey (const PrivateKey &k) | |
| PublicKey () | |
| 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) |
Static Public Member Functions | |
| static PublicKey | fromDER (const QByteArray &a, ConvertResult *result=0, const QString &provider=QString()) |
| static PublicKey | fromPEM (const QString &s, ConvertResult *result=0, const QString &provider=QString()) |
| static PublicKey | fromPEMFile (const QString &fileName, ConvertResult *result=0, const QString &provider=QString()) |
Protected Member Functions | |
| PublicKey (const QString &type, const QString &provider) | |
| QCA::PublicKey::PublicKey | ( | ) |
Create an empty (null) public key.
| QCA::PublicKey::PublicKey | ( | const PrivateKey & | k | ) |
Create a public key based on a specified private key.
| k | the private key to extract the public key parts from |
| QCA::PublicKey::PublicKey | ( | const QString & | fileName | ) |
Import a public key from a PEM representation in a file.
| fileName | the name of the file containing the public key |
| QCA::PublicKey::PublicKey | ( | const PublicKey & | from | ) |
Create a new key of a specified type.
| type | the type of key to create | |
| provider | the provider to use, if required |
| bool QCA::PublicKey::canEncrypt | ( | ) | const |
Test if this key can be used for encryption.
| bool QCA::PublicKey::canVerify | ( | ) | const |
Test if the key can be used for verifying signatures.
| SecureArray QCA::PublicKey::encrypt | ( | const SecureArray & | a, | |
| EncryptionAlgorithm | alg | |||
| ) |
Encrypt a message using a specified algorithm.
| a | the message to encrypt | |
| alg | the algorithm to use |
| static PublicKey QCA::PublicKey::fromDER | ( | const QByteArray & | a, | |
| ConvertResult * | result = 0, |
|||
| 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; }
| a | the array containing a DER encoded key | |
| result | pointer to a variable, which returns whether the conversion succeeded (ConvertGood) or not | |
| provider | the name of the provider to use for the import. |
| static PublicKey QCA::PublicKey::fromPEM | ( | const QString & | s, | |
| ConvertResult * | result = 0, |
|||
| 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; }
| s | the string containing a PEM encoded key | |
| result | pointer to a variable, which returns whether the conversion succeeded (ConvertGood) or not | |
| provider | the name of the provider to use for the import. |
fromPEMFile, which provides an import direct from a file.
| static PublicKey QCA::PublicKey::fromPEMFile | ( | const QString & | fileName, | |
| ConvertResult * | result = 0, |
|||
| 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; }
| fileName | a string containing the name of the file | |
| result | pointer to a variable, which returns whether the conversion succeeded (ConvertGood) or not | |
| provider | the name of the provider to use for the import. |
fromPEM, which provides an import from a string
| int QCA::PublicKey::maximumEncryptSize | ( | EncryptionAlgorithm | alg | ) | const |
The maximum message size that can be encrypted with a specified algorithm.
| alg | the algorithm to check |
| void QCA::PublicKey::startVerify | ( | SignatureAlgorithm | alg, | |
| SignatureFormat | format = DefaultFormat | |||
| ) |
Initialise the signature verification process.
| alg | the algorithm to use for signing | |
| format | the specific format to use, for DSA |
| QByteArray QCA::PublicKey::toDER | ( | ) | const |
Export the key in Distinguished Encoding Rules (DER) format.
| 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.
| 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.
| QString QCA::PublicKey::toPEM | ( | ) | const |
| bool QCA::PublicKey::toPEMFile | ( | const QString & | fileName | ) | const |
Export the key in Privacy Enhanced Mail (PEM) to a file.
| fileName | the name (and path, if necessary) of the file to save the PEM encoded key to. |
fromPEMFile provides an inverse of toPEMFile, reading a PEM encoded key from a file
| 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.
| void QCA::PublicKey::update | ( | const MemoryRegion & | a | ) |
Update the signature verification process with more data.
| a | the array containing the data that should be added to the signature |
| 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 } }
| sig | the signature to check |
| 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.
| a | the message to check the signature on | |
| sig | the signature to be checked | |
| alg | the algorithm to use | |
| format | the signature format to use, for DSA |
1.5.2