#include <QtCrypto>
Generic public key.
- Examples:
- rsatest.cpp.
QCA::PublicKey::PublicKey |
( |
| ) |
|
Create an empty (null) public key.
Create a public key based on a specified private key.
- Parameters
-
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.
- Parameters
-
fileName | the name of the file containing the public key |
- See also
- fromPEMFile for an alternative method
QCA::PublicKey::PublicKey |
( |
const PublicKey & |
from | ) |
|
Copy constructor.
- Parameters
-
QCA::PublicKey::PublicKey |
( |
const QString & |
type, |
|
|
const QString & |
provider |
|
) |
| |
|
protected |
Create a new key of a specified type.
- Parameters
-
type | the type of key to create |
provider | the provider to use, if required |
Assignment operator.
- Parameters
-
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.
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.
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.
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.
bool QCA::PublicKey::canDecrypt |
( |
| ) |
const |
Test if this key can be used for decryption.
- Returns
- true if the key can be used for decryption
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.
The maximum message size that can be encrypted with a specified algorithm.
- Parameters
-
alg | the algorithm to check |
Encrypt a message using a specified algorithm.
- Parameters
-
a | the message to encrypt |
alg | the algorithm to use |
- Examples:
- rsatest.cpp.
Decrypt the message.
- Parameters
-
in | the cipher (encrypted) data |
out | the plain text data |
alg | the 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.
Initialise the signature verification process.
- Parameters
-
alg | the algorithm to use for signing |
format | the specific format to use, for DSA |
- Examples:
- rsatest.cpp.
Update the signature verification process with more data.
- Parameters
-
a | the array containing the data that should be added to the signature |
- Examples:
- rsatest.cpp.
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:
if( pubkey.canVerify() )
{
pubkey.update( theMessage );
if ( pubkey.validSignature( theSignature ) )
{
}
else
{
}
}
- Parameters
-
sig | the signature to check |
- Returns
- true if the signature is correct
- Examples:
- rsatest.cpp.
Single step message verification.
If you have the whole message to be verified, then this offers a more convenient approach to verification.
- Parameters
-
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 |
- Returns
- true if the signature is valid for the message
- Examples:
- rsatest.cpp.
QByteArray QCA::PublicKey::toDER |
( |
| ) |
const |
Export the key in Distinguished Encoding Rules (DER) format.
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
bool QCA::PublicKey::toPEMFile |
( |
const QString & |
fileName | ) |
const |
Export the key in Privacy Enhanced Mail (PEM) to a file.
- Parameters
-
fileName | the 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
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.
{
std::cout << "Public key read failed" << std::endl;
}
- Parameters
-
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.
{
std::cout << "Public key read failed" << std::endl;
}
- Parameters
-
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. |
- See also
- toPEM, which provides an inverse of fromPEM()
-
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.
{
std::cout << "Public key read failed" << std::endl;
}
- Parameters
-
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. |
- 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
The documentation for this class was generated from the following file: