2005-01-01 02:44:28 +00:00
|
|
|
/*
|
|
|
|
* qca_publickey.h - Qt Cryptographic Architecture
|
2007-06-01 23:22:53 +00:00
|
|
|
* Copyright (C) 2003-2007 Justin Karneges <justin@affinix.com>
|
2005-01-01 02:44:28 +00:00
|
|
|
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2008-05-16 20:41:50 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
2005-01-01 02:44:28 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-03-26 03:27:54 +00:00
|
|
|
/**
|
|
|
|
\file qca_publickey.h
|
|
|
|
|
|
|
|
Header file for PublicKey and PrivateKey related classes
|
|
|
|
|
|
|
|
\note You should not use this header directly from an
|
|
|
|
application. You should just use <tt> \#include \<QtCrypto>
|
|
|
|
</tt> instead.
|
|
|
|
*/
|
|
|
|
|
2005-01-01 02:44:28 +00:00
|
|
|
#ifndef QCA_PUBLICKEY_H
|
|
|
|
#define QCA_PUBLICKEY_H
|
|
|
|
|
2005-02-27 01:12:26 +00:00
|
|
|
#include <QObject>
|
2005-01-01 02:44:28 +00:00
|
|
|
#include "qca_core.h"
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
namespace QCA {
|
|
|
|
|
|
|
|
class PublicKey;
|
|
|
|
class PrivateKey;
|
|
|
|
class KeyGenerator;
|
|
|
|
class RSAPublicKey;
|
|
|
|
class RSAPrivateKey;
|
|
|
|
class DSAPublicKey;
|
|
|
|
class DSAPrivateKey;
|
|
|
|
class DHPublicKey;
|
|
|
|
class DHPrivateKey;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Encryption algorithms
|
|
|
|
*/
|
|
|
|
enum EncryptionAlgorithm
|
|
|
|
{
|
2013-11-17 02:06:07 +06:00
|
|
|
EME_PKCS1v15, ///< Block type 2 (PKCS#1, Version 1.5)
|
|
|
|
EME_PKCS1_OAEP, ///< Optimal asymmetric encryption padding (PKCS#1, Version 2.0)
|
|
|
|
EME_PKCS1v15_SSL, ///< PKCS#1, Version 1.5 with an SSL-specific modification
|
|
|
|
EME_NO_PADDING ///< Raw RSA encryption
|
2007-06-01 23:22:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Signature algorithm variants
|
2009-12-15 09:48:04 +00:00
|
|
|
|
|
|
|
Note that most signature algorithms follow a process of first hashing the
|
|
|
|
plaintext data to be signed, creating a payload format that wraps the hash
|
|
|
|
value (among other things), and then signing the payload with the private
|
|
|
|
key. So, for example, an EMSA3(SHA1) signature outputted by QCA cannot be
|
|
|
|
verified by merely performing RSA and SHA1 operations (e.g.
|
|
|
|
"openssl rsautl -verify" and comparing with sha1sum), because that would not
|
|
|
|
take the EMSA3 payload format into consideration.
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
enum SignatureAlgorithm
|
|
|
|
{
|
|
|
|
SignatureUnknown, ///< Unknown signing algorithm
|
|
|
|
EMSA1_SHA1, ///< SHA1, with EMSA1 (IEEE1363-2000) encoding (this is the usual DSA algorithm - FIPS186)
|
|
|
|
EMSA3_SHA1, ///< SHA1, with EMSA3 (ie PKCS#1 Version 1.5) encoding
|
|
|
|
EMSA3_MD5, ///< MD5, with EMSA3 (ie PKCS#1 Version 1.5) encoding (this is the usual RSA algorithm)
|
|
|
|
EMSA3_MD2, ///< MD2, with EMSA3 (ie PKCS#1 Version 1.5) encoding
|
|
|
|
EMSA3_RIPEMD160, ///< RIPEMD160, with EMSA3 (ie PKCS#1 Version 1.5) encoding
|
2009-07-07 12:24:51 +00:00
|
|
|
EMSA3_Raw, ///< EMSA3 without computing a message digest or a DigestInfo encoding (identical to PKCS#11's CKM_RSA_PKCS mechanism)
|
|
|
|
EMSA3_SHA224, ///< SHA224, with EMSA3 (ie PKCS#1 Version 1.5) encoding
|
|
|
|
EMSA3_SHA256, ///< SHA256, with EMSA3 (ie PKCS#1 Version 1.5) encoding
|
|
|
|
EMSA3_SHA384, ///< SHA384, with EMSA3 (ie PKCS#1 Version 1.5) encoding
|
|
|
|
EMSA3_SHA512 ///< SHA512, with EMSA3 (ie PKCS#1 Version 1.5) encoding
|
2007-06-01 23:22:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Signature formats (DSA only)
|
|
|
|
*/
|
|
|
|
enum SignatureFormat
|
|
|
|
{
|
|
|
|
DefaultFormat, ///< For DSA, this is the same as IEEE_1363
|
|
|
|
IEEE_1363, ///< 40-byte format from IEEE 1363 (Botan/.NET)
|
|
|
|
DERSequence ///< Signature wrapped in DER formatting (OpenSSL/Java)
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Password-based encryption
|
|
|
|
*/
|
|
|
|
enum PBEAlgorithm
|
2005-01-01 02:44:28 +00:00
|
|
|
{
|
2007-06-01 23:22:53 +00:00
|
|
|
PBEDefault, ///< Use modern default (same as PBES2_TripleDES_SHA1)
|
|
|
|
PBES2_DES_SHA1, ///< PKCS#5 v2.0 DES/CBC,SHA1
|
|
|
|
PBES2_TripleDES_SHA1, ///< PKCS#5 v2.0 TripleDES/CBC,SHA1
|
|
|
|
PBES2_AES128_SHA1, ///< PKCS#5 v2.0 AES-128/CBC,SHA1
|
|
|
|
PBES2_AES192_SHA1, ///< PKCS#5 v2.0 AES-192/CBC,SHA1
|
|
|
|
PBES2_AES256_SHA1 ///< PKCS#5 v2.0 AES-256/CBC,SHA1
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return value from a format conversion
|
|
|
|
|
|
|
|
Note that if you are checking for any result other than ConvertGood,
|
|
|
|
then you may be introducing a provider specific dependency.
|
|
|
|
*/
|
|
|
|
enum ConvertResult
|
|
|
|
{
|
|
|
|
ConvertGood, ///< Conversion succeeded, results should be valid
|
|
|
|
ErrorDecode, ///< General failure in the decode stage
|
|
|
|
ErrorPassphrase, ///< Failure because of incorrect passphrase
|
|
|
|
ErrorFile ///< Failure because of incorrect file
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Well known discrete logarithm group sets
|
2007-06-02 10:39:17 +00:00
|
|
|
|
|
|
|
These sets are derived from three main sources:
|
|
|
|
Java Cryptographic Extensions,
|
|
|
|
<a href="http://www.ietf.org/rfc/rfc2412.txt">RFC2412</a> and
|
|
|
|
<a href="http://www.ietf.org/rfc/rfc3526.txt">RFC3526</a>.
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
enum DLGroupSet
|
|
|
|
{
|
2007-06-02 10:39:17 +00:00
|
|
|
DSA_512, ///< 512 bit group, for compatibility with JCE
|
|
|
|
DSA_768, ///< 768 bit group, for compatibility with JCE
|
|
|
|
DSA_1024, ///< 1024 bit group, for compatibility with JCE
|
|
|
|
IETF_768, ///< Group 1 from RFC 2412, Section E.1
|
|
|
|
IETF_1024, ///< Group 2 from RFC 2412, Section E.2
|
|
|
|
IETF_1536, ///< 1536-bit MODP Group ("group 5") from RFC3526 Section 2.
|
|
|
|
IETF_2048, ///< 2048-bit MODP Group ("group 14") from RFC3526 Section 3.
|
|
|
|
IETF_3072, ///< 3072-bit MODP Group ("group 15") from RFC3526 Section 4.
|
|
|
|
IETF_4096, ///< 4096-bit MODP Group ("group 16") from RFC3526 Section 5.
|
|
|
|
IETF_6144, ///< 6144-bit MODP Group ("group 17") from RFC3526 Section 6.
|
2007-06-02 11:43:53 +00:00
|
|
|
IETF_8192 ///< 8192-bit MODP Group ("group 18") from RFC3526 Section 7.
|
2007-06-02 10:39:17 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Encode a hash result in EMSA3 (PKCS#1) format
|
|
|
|
|
|
|
|
This is a convenience function for providers that only have access
|
|
|
|
to raw RSA signing (mainly smartcard providers). This is a built-in
|
|
|
|
function of QCA and does not utilize a provider. SHA1, MD5, MD2,
|
|
|
|
and RIPEMD160 are supported.
|
2007-09-03 20:44:32 +00:00
|
|
|
|
|
|
|
\param hashName the hash type used to create the digest
|
|
|
|
\param digest the digest to encode in EMSA3 format
|
|
|
|
\param size the desired size of the encoding output (-1 for automatic size)
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
2007-06-12 23:49:25 +00:00
|
|
|
QCA_EXPORT QByteArray emsa3Encode(const QString &hashName, const QByteArray &digest, int size = -1);
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
\class DLGroup qca_publickey.h QtCrypto
|
|
|
|
|
|
|
|
A discrete logarithm group
|
2007-08-04 08:09:02 +00:00
|
|
|
|
|
|
|
\ingroup UserAPI
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
class QCA_EXPORT DLGroup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DLGroup();
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2005-01-25 13:01:45 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Construct a discrete logarithm group from raw parameters
|
|
|
|
|
2007-09-03 19:51:18 +00:00
|
|
|
\param p the P parameter
|
|
|
|
\param q the Q parameter
|
|
|
|
\param g the G parameter
|
2005-01-25 13:01:45 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
DLGroup(const BigInteger &p, const BigInteger &q, const BigInteger &g);
|
2005-01-25 13:01:45 +00:00
|
|
|
|
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Construct a discrete logarithm group from raw parameters
|
|
|
|
|
2007-09-03 19:51:18 +00:00
|
|
|
\param p the P parameter
|
|
|
|
\param g the G parameter
|
2005-01-25 13:01:45 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
DLGroup(const BigInteger &p, const BigInteger &g);
|
2005-01-25 13:01:45 +00:00
|
|
|
|
2005-03-05 20:50:49 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Standard copy constructor
|
2007-09-03 19:51:18 +00:00
|
|
|
|
|
|
|
\param from the group to copy from
|
2005-03-05 20:50:49 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
DLGroup(const DLGroup &from);
|
|
|
|
~DLGroup();
|
2005-03-05 20:50:49 +00:00
|
|
|
|
2005-01-25 13:01:45 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Standard assignment operator
|
|
|
|
|
|
|
|
\param from the DLGroup to copy from
|
2005-01-25 13:01:45 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
DLGroup & operator=(const DLGroup &from);
|
2005-01-25 13:01:45 +00:00
|
|
|
|
2005-04-10 03:06:51 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Provide a list of the supported group sets
|
2005-04-10 03:06:51 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\param provider the provider to report which group sets are
|
|
|
|
available. If not specified, all providers will be checked
|
2005-04-10 03:06:51 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
static QList<DLGroupSet> supportedGroupSets(const QString &provider = QString());
|
2005-02-25 04:23:12 +00:00
|
|
|
|
2005-04-10 08:17:03 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Test if the group is empty
|
2005-04-10 08:17:03 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
bool isNull() const;
|
2005-03-07 10:23:45 +00:00
|
|
|
|
2007-04-10 21:32:22 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Provide the p component of the group
|
|
|
|
*/
|
|
|
|
BigInteger p() const;
|
2007-04-10 21:32:22 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Provide the q component of the group
|
2007-04-10 21:32:22 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
BigInteger q() const;
|
2007-04-10 21:32:22 +00:00
|
|
|
|
2005-04-10 08:17:03 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Provide the g component of the group
|
|
|
|
*/
|
|
|
|
BigInteger g() const;
|
2006-03-25 10:44:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
private:
|
|
|
|
class Private;
|
|
|
|
Private *d;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
\class PKey qca_publickey.h QtCrypto
|
|
|
|
|
|
|
|
General superclass for public (PublicKey) and private (PrivateKey) keys
|
|
|
|
used with asymmetric encryption techniques.
|
2007-08-04 08:09:02 +00:00
|
|
|
|
|
|
|
\ingroup UserAPI
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
class QCA_EXPORT PKey : public Algorithm
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Types of public key cryptography keys supported by QCA
|
2005-04-10 08:17:03 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
enum Type {
|
|
|
|
RSA, ///< RSA key
|
|
|
|
DSA, ///< DSA key
|
|
|
|
DH ///< Diffie Hellman key
|
2005-03-07 10:23:45 +00:00
|
|
|
};
|
|
|
|
|
2007-09-03 19:51:18 +00:00
|
|
|
/**
|
|
|
|
Standard constructor
|
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
PKey();
|
|
|
|
|
2005-04-10 03:06:51 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Standard copy constructor
|
2006-03-25 10:44:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\param from the key to copy from
|
2005-04-10 03:06:51 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
PKey(const PKey &from);
|
2007-09-03 19:51:18 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
~PKey();
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Standard assignment operator
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\param from the PKey to copy from
|
|
|
|
*/
|
|
|
|
PKey & operator=(const PKey &from);
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Test what types of keys are supported.
|
|
|
|
|
|
|
|
Normally you would just test if the capability is present, however
|
|
|
|
for PKey, you also need to test which types of keys are available.
|
|
|
|
So if you want to figure out if RSA keys are supported, you need to
|
|
|
|
do something like:
|
|
|
|
\code
|
|
|
|
if(!QCA::isSupported("pkey") ||
|
|
|
|
!QCA::PKey::supportedTypes().contains(QCA::PKey::RSA))
|
|
|
|
{
|
|
|
|
// then there is no RSA key support
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// there is RSA key support
|
|
|
|
}
|
|
|
|
\endcode
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
To make things a bit more complex, supportedTypes() only
|
|
|
|
checks for basic functionality. If you want to check that
|
|
|
|
you can do operations with PEM or DER (eg toPEM(), fromPEM(), and
|
|
|
|
the equivalent DER and PEMfile operations, plus anything else
|
|
|
|
that uses them, including the constructor form that takes a
|
|
|
|
fileName), then you need to check for supportedIOTypes() instead.
|
2005-03-03 21:56:23 +00:00
|
|
|
|
2007-09-03 12:04:55 +00:00
|
|
|
\param provider the name of the provider to use, if a particular
|
|
|
|
provider is required.
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa supportedIOTypes()
|
|
|
|
*/
|
|
|
|
static QList<Type> supportedTypes(const QString &provider = QString());
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2005-04-10 03:06:51 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Test what types of keys are supported for IO operations
|
|
|
|
|
|
|
|
If you are using PKey DER or PEM operations, then you need
|
|
|
|
to check for appropriate support using this method. For example,
|
|
|
|
if you want to check if you can export or import an RSA key, then
|
|
|
|
you need to do something like:
|
|
|
|
\code
|
|
|
|
if(!QCA::isSupported("pkey") ||
|
|
|
|
!QCA::PKey::supportedIOTypes().contains(QCA::PKey::RSA))
|
|
|
|
{
|
|
|
|
// then there is no RSA key IO support
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// there is RSA key IO support
|
|
|
|
}
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
Note that if you only want to check for basic functionality
|
|
|
|
(ie not PEM or DER import/export), then you can use
|
|
|
|
supportedTypes(). There is no need to use both - if the key type
|
|
|
|
is supported for IO, then is also supported for basic operations.
|
2006-03-25 10:44:30 +00:00
|
|
|
|
2007-09-03 12:04:55 +00:00
|
|
|
\param provider the name of the provider to use, if a particular
|
|
|
|
provider is required.
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa supportedTypes()
|
2005-04-10 03:06:51 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
static QList<Type> supportedIOTypes(const QString &provider = QString());
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2005-04-10 03:06:51 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Test if the key is null (empty)
|
2006-03-25 10:44:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\return true if the key is null
|
2005-04-10 03:06:51 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
bool isNull() const;
|
2005-05-19 12:04:08 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Report the Type of key (eg RSA, DSA or Diffie Hellman)
|
2005-05-19 12:04:08 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa isRSA, isDSA and isDH for boolean tests.
|
|
|
|
*/
|
|
|
|
Type type() const;
|
2005-05-19 12:04:08 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Report the number of bits in the key
|
|
|
|
*/
|
|
|
|
int bitSize() const;
|
2005-05-19 12:04:08 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Test if the key is an RSA key
|
|
|
|
*/
|
|
|
|
bool isRSA() const;
|
2005-05-21 05:13:31 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Test if the key is a DSA key
|
|
|
|
*/
|
|
|
|
bool isDSA() const;
|
2005-05-21 05:13:31 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Test if the key is a Diffie Hellman key
|
|
|
|
*/
|
|
|
|
bool isDH() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Test if the key is a public key
|
|
|
|
*/
|
|
|
|
bool isPublic() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Test if the key is a private key
|
|
|
|
*/
|
|
|
|
bool isPrivate() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Test if the key data can be exported. If the key resides on a
|
|
|
|
smart card or other such device, this will likely return false.
|
|
|
|
*/
|
|
|
|
bool canExport() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Test if the key can be used for key agreement
|
|
|
|
*/
|
|
|
|
bool canKeyAgree() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Interpret this key as a PublicKey
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa toRSAPublicKey(), toDSAPublicKey() and toDHPublicKey()
|
|
|
|
for protected forms of this call.
|
|
|
|
*/
|
|
|
|
PublicKey toPublicKey() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Interpret this key as a PrivateKey
|
|
|
|
*/
|
|
|
|
PrivateKey toPrivateKey() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
test if two keys are equal
|
2007-09-03 12:04:55 +00:00
|
|
|
|
|
|
|
\param a the key to compare with this key
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
bool operator==(const PKey &a) const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
test if two keys are not equal
|
2007-09-03 12:04:55 +00:00
|
|
|
|
|
|
|
\param a the key to compare with this key
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
bool operator!=(const PKey &a) const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
Create a key of the specified type
|
2007-09-03 20:59:10 +00:00
|
|
|
|
|
|
|
\param type the name of the type of key to create
|
|
|
|
\param provider the name of the provider to create the key in
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
PKey(const QString &type, const QString &provider);
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Set the key
|
2007-09-03 12:04:55 +00:00
|
|
|
|
|
|
|
\param k the key to assign from
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
void set(const PKey &k);
|
2007-05-05 07:31:08 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Interpret this key as an RSAPublicKey
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\note This function is essentially a convenience cast - if the
|
|
|
|
key was created as a DSA key, this function cannot turn it into
|
|
|
|
an RSA key.
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa toPublicKey() for the public version of this method
|
|
|
|
*/
|
|
|
|
RSAPublicKey toRSAPublicKey() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Interpret this key as an RSAPrivateKey
|
2007-05-05 07:31:08 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\note This function is essentially a convenience cast - if the
|
|
|
|
key was created as a DSA key, this function cannot turn it into
|
|
|
|
a RSA key.
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa toPrivateKey() for the public version of this method
|
|
|
|
*/
|
|
|
|
RSAPrivateKey toRSAPrivateKey() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Interpret this key as an DSAPublicKey
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\note This function is essentially a convenience cast - if the
|
|
|
|
key was created as an RSA key, this function cannot turn it into
|
|
|
|
a DSA key.
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa toPublicKey() for the public version of this method
|
|
|
|
*/
|
|
|
|
DSAPublicKey toDSAPublicKey() const;
|
2007-05-05 07:31:08 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Interpret this key as a DSAPrivateKey
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\note This function is essentially a convenience cast - if the
|
|
|
|
key was created as an RSA key, this function cannot turn it into
|
|
|
|
a DSA key.
|
2005-05-19 12:04:08 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa toPrivateKey() for the public version of this method
|
|
|
|
*/
|
|
|
|
DSAPrivateKey toDSAPrivateKey() const;
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2005-04-10 03:06:51 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Interpret this key as an DHPublicKey
|
2006-03-25 10:44:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\note This function is essentially a convenience cast - if the
|
|
|
|
key was created as a DSA key, this function cannot turn it into
|
|
|
|
a DH key.
|
2005-04-10 03:06:51 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa toPublicKey() for the public version of this method
|
2005-04-10 03:06:51 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
DHPublicKey toDHPublicKey() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Interpret this key as a DHPrivateKey
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\note This function is essentially a convenience cast - if the
|
|
|
|
key was created as a DSA key, this function cannot turn it into
|
|
|
|
a DH key.
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa toPrivateKey() for the public version of this method
|
|
|
|
*/
|
|
|
|
DHPrivateKey toDHPrivateKey() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
private:
|
|
|
|
void assignToPublic(PKey *dest) const;
|
|
|
|
void assignToPrivate(PKey *dest) const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
class Private;
|
|
|
|
Private *d;
|
|
|
|
};
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
\class PublicKey qca_publickey.h QtCrypto
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
Generic public key
|
2007-08-04 08:09:02 +00:00
|
|
|
|
|
|
|
\ingroup UserAPI
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
class QCA_EXPORT PublicKey : public PKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Create an empty (null) public key
|
|
|
|
*/
|
|
|
|
PublicKey();
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Create a public key based on a specified private key
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\param k the private key to extract the public key parts from
|
|
|
|
*/
|
|
|
|
PublicKey(const PrivateKey &k);
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Import a public key from a PEM representation in a file
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\param fileName the name of the file containing the public key
|
2005-04-10 08:17:03 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa fromPEMFile for an alternative method
|
|
|
|
*/
|
|
|
|
PublicKey(const QString &fileName);
|
2005-04-10 08:17:03 +00:00
|
|
|
|
2007-06-02 00:24:30 +00:00
|
|
|
/**
|
|
|
|
Copy constructor
|
|
|
|
|
|
|
|
\param from the PublicKey to copy from
|
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
PublicKey(const PublicKey &from);
|
2007-06-02 00:24:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
~PublicKey();
|
2007-06-02 00:24:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Assignment operator
|
|
|
|
|
|
|
|
\param from the PublicKey to copy from
|
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
PublicKey & operator=(const PublicKey &from);
|
2005-04-10 08:17:03 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Convenience method to convert this key to an RSAPublicKey
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
Note that if the key is not an RSA key (eg it is DSA or DH),
|
|
|
|
then this will produce a null key.
|
|
|
|
*/
|
|
|
|
RSAPublicKey toRSA() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Convenience method to convert this key to a DSAPublicKey
|
2005-09-11 06:38:41 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
Note that if the key is not an DSA key (eg it is RSA or DH),
|
|
|
|
then this will produce a null key.
|
|
|
|
*/
|
|
|
|
DSAPublicKey toDSA() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Convenience method to convert this key to a DHPublicKey
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
Note that if the key is not an DH key (eg it is DSA or RSA),
|
|
|
|
then this will produce a null key.
|
|
|
|
*/
|
|
|
|
DHPublicKey toDH() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Test if this key can be used for encryption
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\return true if the key can be used for encryption
|
|
|
|
*/
|
|
|
|
bool canEncrypt() const;
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2013-12-16 22:15:49 +01:00
|
|
|
/**
|
|
|
|
Test if this key can be used for decryption
|
|
|
|
|
|
|
|
\return true if the key can be used for decryption
|
|
|
|
*/
|
|
|
|
bool canDecrypt() const;
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Test if the key can be used for verifying signatures
|
2005-03-07 10:23:45 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\return true of the key can be used for verification
|
|
|
|
*/
|
|
|
|
bool canVerify() const;
|
2005-05-21 05:13:31 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
The maximum message size that can be encrypted with a specified
|
|
|
|
algorithm
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\param alg the algorithm to check
|
|
|
|
*/
|
|
|
|
int maximumEncryptSize(EncryptionAlgorithm alg) const;
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Encrypt a message using a specified algorithm
|
2005-05-18 12:15:21 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\param a the message to encrypt
|
|
|
|
\param alg the algorithm to use
|
|
|
|
*/
|
|
|
|
SecureArray encrypt(const SecureArray &a, EncryptionAlgorithm alg);
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2013-12-16 22:15:49 +01:00
|
|
|
/**
|
|
|
|
Decrypt the message
|
|
|
|
|
|
|
|
\param in the cipher (encrypted) data
|
|
|
|
\param out the plain text data
|
|
|
|
\param 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.
|
|
|
|
*/
|
|
|
|
bool decrypt(const SecureArray &in, SecureArray *out, EncryptionAlgorithm alg);
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Initialise the signature verification process
|
2007-05-30 07:02:34 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\param alg the algorithm to use for signing
|
|
|
|
\param format the specific format to use, for DSA
|
|
|
|
*/
|
|
|
|
void startVerify(SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2005-04-10 03:06:51 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Update the signature verification process with more data
|
2006-03-25 10:44:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\param a the array containing the data that should be added to the signature
|
2005-04-10 03:06:51 +00:00
|
|
|
*/
|
2007-06-18 21:31:14 +00:00
|
|
|
void update(const MemoryRegion &a);
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Check the signature is valid for the message
|
|
|
|
|
|
|
|
The process to check that a signature is correct is shown below:
|
|
|
|
\code
|
|
|
|
// 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 ) )
|
2005-01-01 02:44:28 +00:00
|
|
|
{
|
2007-06-01 23:22:53 +00:00
|
|
|
// then signature is valid
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// then signature is invalid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
\param sig the signature to check
|
|
|
|
|
|
|
|
\return true if the signature is correct
|
|
|
|
*/
|
2007-06-12 23:49:25 +00:00
|
|
|
bool validSignature(const QByteArray &sig);
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2005-04-10 03:06:51 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Single step message verification
|
2006-03-25 10:44:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
If you have the whole message to be verified, then this offers a
|
|
|
|
more convenient approach to verification.
|
|
|
|
|
|
|
|
\param a the message to check the signature on
|
|
|
|
\param sig the signature to be checked
|
|
|
|
\param alg the algorithm to use
|
|
|
|
\param format the signature format to use, for DSA
|
|
|
|
|
|
|
|
\return true if the signature is valid for the message
|
2005-04-10 03:06:51 +00:00
|
|
|
*/
|
2007-06-18 21:31:14 +00:00
|
|
|
bool verifyMessage(const MemoryRegion &a, const QByteArray &sig, SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2005-04-10 03:06:51 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Export the key in Distinguished Encoding Rules (DER) format
|
|
|
|
*/
|
2007-06-12 23:49:25 +00:00
|
|
|
QByteArray toDER() const;
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Export the key in Privacy Enhanced Mail (PEM) format
|
2006-03-25 10:44:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa toPEMFile provides a convenient way to save the PEM encoded key
|
|
|
|
to a file
|
|
|
|
\sa fromPEM provides an inverse of toPEM, converting the PEM
|
|
|
|
encoded key back to a PublicKey
|
2005-04-10 03:06:51 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
QString toPEM() const;
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2005-04-10 03:06:51 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
Export the key in Privacy Enhanced Mail (PEM) to a file
|
|
|
|
|
|
|
|
\param fileName the name (and path, if necessary) of the file to
|
|
|
|
save the PEM encoded key to.
|
2006-03-25 10:44:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\sa toPEM for a version that exports to a QString, which may be
|
|
|
|
useful if you need to do more sophisticated handling
|
|
|
|
\sa fromPEMFile provides an inverse of toPEMFile, reading a PEM
|
|
|
|
encoded key from a file
|
2005-04-10 03:06:51 +00:00
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
bool toPEMFile(const QString &fileName) const;
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2005-04-10 03:06:51 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
\code
|
|
|
|
QCA::ConvertResult conversionResult;
|
|
|
|
QCA::PublicKey publicKey = QCA::PublicKey::fromDER(keyArray, &conversionResult);
|
|
|
|
if (! QCA::ConvertGood == conversionResult)
|
|
|
|
{
|
|
|
|
std::cout << "Public key read failed" << std::endl;
|
|
|
|
}
|
|
|
|
\endcode
|
2006-03-25 10:44:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\param a the array containing a DER encoded key
|
|
|
|
\param result pointer to a variable, which returns whether the
|
|
|
|
conversion succeeded (ConvertGood) or not
|
|
|
|
\param provider the name of the provider to use for the import.
|
2005-04-10 03:06:51 +00:00
|
|
|
*/
|
2020-01-20 13:37:51 +01:00
|
|
|
static PublicKey fromDER(const QByteArray &a, ConvertResult *result = nullptr, const QString &provider = QString());
|
2005-01-01 02:44:28 +00:00
|
|
|
|
2005-04-10 03:06:51 +00:00
|
|
|
/**
|
2007-06-01 23:22:53 +00:00
|
|
|
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.
|
2006-03-25 10:44:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
\code
|
|
|
|
QCA::ConvertResult conversionResult;
|
|
|
|
QCA::PublicKey publicKey = QCA::PublicKey::fromPEM(keyAsString, &conversionResult);
|
|
|
|
if (! QCA::ConvertGood == conversionResult)
|
|
|
|
{
|
|
|
|
std::cout << "Public key read failed" << std::endl;
|
|
|
|
}
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
\param s the string containing a PEM encoded key
|
|
|
|
\param result pointer to a variable, which returns whether the
|
|
|
|
conversion succeeded (ConvertGood) or not
|
|
|
|
\param provider the name of the provider to use for the import.
|
|
|
|
|
|
|
|
\sa toPEM, which provides an inverse of fromPEM()
|
|
|
|
\sa fromPEMFile, which provides an import direct from a file.
|
2005-04-10 03:06:51 +00:00
|
|
|
*/
|
2020-01-20 13:37:51 +01:00
|
|
|
static PublicKey fromPEM(const QString &s, ConvertResult *result = nullptr, const QString &provider = QString());
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
|
|
|
|
|
|
|
\code
|
|
|
|
QCA::ConvertResult conversionResult;
|
|
|
|
QCA::PublicKey publicKey = QCA::PublicKey::fromPEMFile(fileName, &conversionResult);
|
|
|
|
if (! QCA::ConvertGood == conversionResult)
|
|
|
|
{
|
|
|
|
std::cout << "Public key read failed" << std::endl;
|
|
|
|
}
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
\param fileName a string containing the name of the file
|
|
|
|
\param result pointer to a variable, which returns whether the
|
|
|
|
conversion succeeded (ConvertGood) or not
|
|
|
|
\param provider the name of the provider to use for the import.
|
|
|
|
|
|
|
|
\sa toPEMFile, which provides an inverse of fromPEMFile()
|
|
|
|
\sa fromPEM, which provides an import from a string
|
|
|
|
|
|
|
|
\note there is also a constructor form that can import from a file
|
|
|
|
*/
|
2020-01-20 13:37:51 +01:00
|
|
|
static PublicKey fromPEMFile(const QString &fileName, ConvertResult *result = nullptr, const QString &provider = QString());
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
Create a new key of a specified type
|
|
|
|
|
|
|
|
\param type the type of key to create
|
|
|
|
\param provider the provider to use, if required
|
|
|
|
*/
|
|
|
|
PublicKey(const QString &type, const QString &provider);
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Private;
|
|
|
|
Private *d;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
\class PrivateKey qca_publickey.h QtCrypto
|
|
|
|
|
|
|
|
Generic private key
|
2007-08-04 08:09:02 +00:00
|
|
|
|
|
|
|
\ingroup UserAPI
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
class QCA_EXPORT PrivateKey : public PKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Create an empty private key
|
|
|
|
*/
|
|
|
|
PrivateKey();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Import a private key from a PEM representation in a file
|
|
|
|
|
|
|
|
\param fileName the name of the file containing the private key
|
|
|
|
\param passphrase the pass phrase for the private key
|
|
|
|
|
|
|
|
\sa fromPEMFile for an alternative method
|
2007-06-08 23:34:31 +00:00
|
|
|
|
|
|
|
\note This synchronous operation may require event handling, and so
|
|
|
|
it must not be called from the same thread as an EventHandler.
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
explicit PrivateKey(const QString &fileName, const SecureArray &passphrase = SecureArray());
|
|
|
|
|
2007-06-02 00:24:30 +00:00
|
|
|
/**
|
|
|
|
Copy constructor
|
|
|
|
|
|
|
|
\param from the PrivateKey to copy from
|
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
PrivateKey(const PrivateKey &from);
|
2007-06-02 00:24:30 +00:00
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
~PrivateKey();
|
2007-06-02 00:24:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Assignment operator
|
|
|
|
|
|
|
|
\param from the PrivateKey to copy from
|
|
|
|
*/
|
2007-06-01 23:22:53 +00:00
|
|
|
PrivateKey & operator=(const PrivateKey &from);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Interpret / convert the key to an RSA key
|
|
|
|
*/
|
|
|
|
RSAPrivateKey toRSA() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Interpret / convert the key to a DSA key
|
|
|
|
*/
|
|
|
|
DSAPrivateKey toDSA() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Interpret / convert the key to a Diffie-Hellman key
|
|
|
|
*/
|
|
|
|
DHPrivateKey toDH() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Test if this key can be used for decryption
|
|
|
|
|
|
|
|
\return true if the key can be used for decryption
|
|
|
|
*/
|
|
|
|
bool canDecrypt() const;
|
|
|
|
|
2013-12-16 22:15:49 +01:00
|
|
|
/**
|
|
|
|
Test if this key can be used for encryption
|
|
|
|
|
|
|
|
\return true if the key can be used for encryption
|
|
|
|
*/
|
|
|
|
bool canEncrypt() const;
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Test if this key can be used for signing
|
|
|
|
|
|
|
|
\return true if the key can be used to make a signature
|
|
|
|
*/
|
|
|
|
bool canSign() const;
|
|
|
|
|
2013-12-16 22:15:49 +01:00
|
|
|
/**
|
|
|
|
The maximum message size that can be encrypted with a specified
|
|
|
|
algorithm
|
|
|
|
|
|
|
|
\param alg the algorithm to check
|
|
|
|
*/
|
|
|
|
int maximumEncryptSize(EncryptionAlgorithm alg) const;
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Decrypt the message
|
|
|
|
|
|
|
|
\param in the cipher (encrypted) data
|
|
|
|
\param out the plain text data
|
|
|
|
\param alg the algorithm to use
|
2007-06-08 23:34:31 +00:00
|
|
|
|
|
|
|
\note This synchronous operation may require event handling, and so
|
|
|
|
it must not be called from the same thread as an EventHandler.
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
bool decrypt(const SecureArray &in, SecureArray *out, EncryptionAlgorithm alg);
|
|
|
|
|
2013-12-16 22:15:49 +01:00
|
|
|
/**
|
|
|
|
Encrypt a message using a specified algorithm
|
|
|
|
|
|
|
|
\param a the message to encrypt
|
|
|
|
\param alg the algorithm to use
|
|
|
|
*/
|
|
|
|
SecureArray encrypt(const SecureArray &a, EncryptionAlgorithm alg);
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
/**
|
|
|
|
Initialise the message signature process
|
|
|
|
|
|
|
|
\param alg the algorithm to use for the message signature process
|
|
|
|
\param format the signature format to use, for DSA
|
2007-06-08 23:34:31 +00:00
|
|
|
|
|
|
|
\note This synchronous operation may require event handling, and so
|
|
|
|
it must not be called from the same thread as an EventHandler.
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
void startSign(SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Update the signature process
|
|
|
|
|
|
|
|
\param a the message to use to update the signature
|
2007-06-08 23:34:31 +00:00
|
|
|
|
|
|
|
\note This synchronous operation may require event handling, and so
|
|
|
|
it must not be called from the same thread as an EventHandler.
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
2007-06-18 21:31:14 +00:00
|
|
|
void update(const MemoryRegion &a);
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
The resulting signature
|
2007-06-08 23:34:31 +00:00
|
|
|
|
|
|
|
\note This synchronous operation may require event handling, and so
|
|
|
|
it must not be called from the same thread as an EventHandler.
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
2007-06-12 23:49:25 +00:00
|
|
|
QByteArray signature();
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
One step signature process
|
|
|
|
|
|
|
|
\param a the message to sign
|
|
|
|
\param alg the algorithm to use for the signature
|
|
|
|
\param format the signature format to use, for DSA
|
|
|
|
|
|
|
|
\return the signature
|
2007-06-08 23:34:31 +00:00
|
|
|
|
|
|
|
\note This synchronous operation may require event handling, and so
|
|
|
|
it must not be called from the same thread as an EventHandler.
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
2007-06-18 21:31:14 +00:00
|
|
|
QByteArray signMessage(const MemoryRegion &a, SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Derive a shared secret key from a public key
|
|
|
|
|
|
|
|
\param theirs the public key to derive from
|
|
|
|
*/
|
|
|
|
SymmetricKey deriveKey(const PublicKey &theirs);
|
|
|
|
|
|
|
|
/**
|
|
|
|
List the supported Password Based Encryption Algorithms that can be
|
|
|
|
used to protect the key.
|
|
|
|
|
|
|
|
\param provider the provider to use, if a particular provider is
|
|
|
|
required
|
|
|
|
*/
|
|
|
|
static QList<PBEAlgorithm> supportedPBEAlgorithms(const QString &provider = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
Export the key in Distinguished Encoding Rules (DER) format
|
|
|
|
|
|
|
|
\param passphrase the pass phrase to use to protect the key
|
|
|
|
\param pbe the symmetric encryption algorithm to use to protect the
|
|
|
|
key
|
|
|
|
|
|
|
|
\sa fromDER provides an inverse of toDER, converting the DER
|
|
|
|
encoded key back to a PrivateKey
|
|
|
|
*/
|
|
|
|
SecureArray toDER(const SecureArray &passphrase = SecureArray(), PBEAlgorithm pbe = PBEDefault) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Export the key in Privacy Enhanced Mail (PEM) format
|
|
|
|
|
|
|
|
\param passphrase the pass phrase to use to protect the key
|
|
|
|
\param pbe the symmetric encryption algorithm to use to protect the
|
|
|
|
key
|
|
|
|
|
|
|
|
\sa toPEMFile provides a convenient way to save the PEM encoded key
|
|
|
|
to a file
|
|
|
|
\sa fromPEM provides an inverse of toPEM, converting the PEM
|
|
|
|
encoded key back to a PrivateKey
|
|
|
|
*/
|
|
|
|
QString toPEM(const SecureArray &passphrase = SecureArray(), PBEAlgorithm pbe = PBEDefault) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Export the key in Privacy Enhanced Mail (PEM) format to a file
|
|
|
|
|
|
|
|
\param fileName the name (and path, if required) that the key
|
|
|
|
should be exported to.
|
|
|
|
\param passphrase the pass phrase to use to protect the key
|
|
|
|
\param pbe the symmetric encryption algorithm to use to protect the
|
|
|
|
key
|
|
|
|
|
|
|
|
\return true if the export succeeds
|
|
|
|
|
|
|
|
\sa toPEM provides a convenient way to save the PEM encoded key to
|
|
|
|
a file
|
|
|
|
\sa fromPEM provides an inverse of toPEM, converting the PEM
|
|
|
|
encoded key back to a PrivateKey
|
|
|
|
*/
|
|
|
|
bool toPEMFile(const QString &fileName, const SecureArray &passphrase = SecureArray(), PBEAlgorithm pbe = PBEDefault) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Import the key from Distinguished Encoding Rules (DER) format
|
|
|
|
|
|
|
|
\param a the array containing the DER representation of the key
|
|
|
|
\param passphrase the pass phrase that is used to protect the key
|
|
|
|
\param result a pointer to a ConvertResult, that if specified, will
|
|
|
|
be set to reflect the result of the import
|
|
|
|
\param provider the provider to use, if a particular provider is
|
|
|
|
required
|
|
|
|
|
|
|
|
\sa toDER provides an inverse of fromDER, exporting the key to an
|
|
|
|
array
|
|
|
|
|
|
|
|
\sa QCA::KeyLoader for an asynchronous loader approach.
|
2007-06-08 23:34:31 +00:00
|
|
|
|
|
|
|
\note This synchronous operation may require event handling, and so
|
|
|
|
it must not be called from the same thread as an EventHandler.
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
2020-01-20 13:37:51 +01:00
|
|
|
static PrivateKey fromDER(const SecureArray &a, const SecureArray &passphrase = SecureArray(), ConvertResult *result = nullptr, const QString &provider = QString());
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Import the key from Privacy Enhanced Mail (PEM) format
|
|
|
|
|
|
|
|
\param s the string containing the PEM representation of the key
|
|
|
|
\param passphrase the pass phrase that is used to protect the key
|
|
|
|
\param result a pointer to a ConvertResult, that if specified, will
|
|
|
|
be set to reflect the result of the import
|
|
|
|
\param provider the provider to use, if a particular provider is
|
|
|
|
required
|
|
|
|
|
|
|
|
\sa toPEM provides an inverse of fromPEM, exporting the key to a
|
|
|
|
string in PEM encoding.
|
|
|
|
|
|
|
|
\sa QCA::KeyLoader for an asynchronous loader approach.
|
2007-06-08 23:34:31 +00:00
|
|
|
|
|
|
|
\note This synchronous operation may require event handling, and so
|
|
|
|
it must not be called from the same thread as an EventHandler.
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
2020-01-20 13:37:51 +01:00
|
|
|
static PrivateKey fromPEM(const QString &s, const SecureArray &passphrase = SecureArray(), ConvertResult *result = nullptr, const QString &provider = QString());
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Import the key in Privacy Enhanced Mail (PEM) format from a file
|
|
|
|
|
|
|
|
\param fileName the name (and path, if required) of the file
|
|
|
|
containing the PEM representation of the key
|
|
|
|
\param passphrase the pass phrase that is used to protect the key
|
|
|
|
\param result a pointer to a ConvertResult, that if specified, will
|
|
|
|
be set to reflect the result of the import
|
|
|
|
\param provider the provider to use, if a particular provider is
|
|
|
|
required
|
|
|
|
|
|
|
|
\sa toPEMFile provides an inverse of fromPEMFile
|
|
|
|
\sa fromPEM which allows import from a string
|
|
|
|
|
|
|
|
\sa QCA::KeyLoader for an asynchronous loader approach.
|
|
|
|
|
|
|
|
\note there is also a constructor form, that allows you to create
|
|
|
|
the key directly
|
2007-06-08 23:34:31 +00:00
|
|
|
|
|
|
|
\note This synchronous operation may require event handling, and so
|
|
|
|
it must not be called from the same thread as an EventHandler.
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
2020-01-20 13:37:51 +01:00
|
|
|
static PrivateKey fromPEMFile(const QString &fileName, const SecureArray &passphrase = SecureArray(), ConvertResult *result = nullptr, const QString &provider = QString());
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
Create a new private key
|
|
|
|
|
|
|
|
\param type the type of key to create
|
|
|
|
\param provider the provider to use, if a specific provider is
|
|
|
|
required.
|
|
|
|
*/
|
|
|
|
PrivateKey(const QString &type, const QString &provider);
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Private;
|
|
|
|
Private *d;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
\class KeyGenerator qca_publickey.h QtCrypto
|
|
|
|
|
|
|
|
Class for generating asymmetric key pairs
|
|
|
|
|
|
|
|
This class is used for generating asymmetric keys (public/private key
|
2007-08-04 08:09:02 +00:00
|
|
|
pairs).
|
|
|
|
|
|
|
|
\ingroup UserAPI
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
class QCA_EXPORT KeyGenerator : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Create a new key generator
|
|
|
|
|
|
|
|
\param parent the parent object, if applicable
|
|
|
|
*/
|
2020-01-20 13:37:51 +01:00
|
|
|
KeyGenerator(QObject *parent = nullptr);
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
~KeyGenerator();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Test whether the key generator is set to operate in blocking mode,
|
|
|
|
or not
|
|
|
|
|
|
|
|
\return true if the key generator is in blocking mode
|
|
|
|
|
2007-06-08 20:31:50 +00:00
|
|
|
\sa setBlockingEnabled
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
2007-06-08 20:31:50 +00:00
|
|
|
bool blockingEnabled() const;
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Set whether the key generator is in blocking mode, nor not
|
|
|
|
|
|
|
|
\param b if true, the key generator will be set to operate in
|
|
|
|
blocking mode, otherwise it will operate in non-blocking mode
|
|
|
|
|
2007-06-08 20:31:50 +00:00
|
|
|
\sa blockingEnabled()
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
2007-06-08 20:31:50 +00:00
|
|
|
void setBlockingEnabled(bool b);
|
2007-06-01 23:22:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Test if the key generator is currently busy, or not
|
|
|
|
|
|
|
|
\return true if the key generator is busy generating a key already
|
|
|
|
*/
|
|
|
|
bool isBusy() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Generate an RSA key of the specified length
|
|
|
|
|
|
|
|
This method creates both the public key and corresponding private
|
|
|
|
key. You almost certainly want to extract the public key part out -
|
|
|
|
see PKey::toPublicKey for an easy way.
|
|
|
|
|
|
|
|
Key length is a tricky judgment - using less than 2048 is probably
|
|
|
|
being too liberal for long term use. Don't use less than 1024
|
|
|
|
without serious analysis.
|
|
|
|
|
|
|
|
\param bits the length of key that is required
|
|
|
|
\param exp the exponent - typically 3, 17 or 65537
|
|
|
|
\param provider the name of the provider to use, if a particular
|
|
|
|
provider is required
|
|
|
|
*/
|
|
|
|
PrivateKey createRSA(int bits, int exp = 65537, const QString &provider = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
Generate a DSA key
|
|
|
|
|
|
|
|
This method creates both the public key and corresponding private
|
|
|
|
key. You almost certainly want to extract the public key part out -
|
|
|
|
see PKey::toPublicKey for an easy way.
|
|
|
|
|
|
|
|
\param domain the discrete logarithm group that this key should be
|
|
|
|
generated from
|
|
|
|
\param provider the name of the provider to use, if a particular
|
|
|
|
provider is required
|
|
|
|
|
|
|
|
\note Not every DLGroup makes sense for DSA. You should use one of
|
|
|
|
DSA_512, DSA_768 and DSA_1024.
|
|
|
|
*/
|
|
|
|
PrivateKey createDSA(const DLGroup &domain, const QString &provider = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
Generate a Diffie-Hellman key
|
|
|
|
|
|
|
|
This method creates both the public key and corresponding private
|
|
|
|
key. You almost certainly want to extract the public key part out -
|
|
|
|
see PKey::toPublicKey for an easy way.
|
|
|
|
|
|
|
|
\param domain the discrete logarithm group that this key should be
|
|
|
|
generated from
|
|
|
|
\param provider the name of the provider to use, if a particular
|
|
|
|
provider is required
|
|
|
|
\note For compatibility, you should use one of the IETF_ groupsets
|
|
|
|
as the domain argument.
|
|
|
|
*/
|
|
|
|
PrivateKey createDH(const DLGroup &domain, const QString &provider = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return the last generated key
|
|
|
|
|
|
|
|
This is really only useful when you are working with non-blocking
|
|
|
|
key generation
|
|
|
|
*/
|
|
|
|
PrivateKey key() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create a new discrete logarithm group
|
|
|
|
|
|
|
|
\param set the set of discrete logarithm parameters to generate
|
|
|
|
from
|
|
|
|
\param provider the name of the provider to use, if a particular
|
|
|
|
provider is required.
|
|
|
|
*/
|
|
|
|
DLGroup createDLGroup(QCA::DLGroupSet set, const QString &provider = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
The current discrete logarithm group
|
|
|
|
*/
|
|
|
|
DLGroup dlGroup() const;
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
Emitted when the key generation is complete.
|
|
|
|
|
|
|
|
This is only used in non-blocking mode
|
|
|
|
*/
|
|
|
|
void finished();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY(KeyGenerator)
|
|
|
|
|
|
|
|
class Private;
|
|
|
|
friend class Private;
|
|
|
|
Private *d;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
\class RSAPublicKey qca_publickey.h QtCrypto
|
|
|
|
|
|
|
|
RSA Public Key
|
2007-08-04 08:09:02 +00:00
|
|
|
|
|
|
|
\ingroup UserAPI
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
class QCA_EXPORT RSAPublicKey : public PublicKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Generate an empty RSA public key
|
|
|
|
*/
|
|
|
|
RSAPublicKey();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Generate an RSA public key from specified parameters
|
|
|
|
|
|
|
|
\param n the public key value
|
|
|
|
\param e the public key exponent
|
|
|
|
\param provider the provider to use, if a particular provider is
|
|
|
|
required
|
|
|
|
*/
|
|
|
|
RSAPublicKey(const BigInteger &n, const BigInteger &e, const QString &provider = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
Extract the public key components from an RSA private key
|
|
|
|
|
|
|
|
\param k the private key to use as the basis for the public key
|
|
|
|
*/
|
|
|
|
RSAPublicKey(const RSAPrivateKey &k);
|
|
|
|
|
|
|
|
/**
|
|
|
|
The public key value
|
|
|
|
|
|
|
|
This value is the actual public key value (the product of p and q,
|
|
|
|
the random prime numbers used to generate the RSA key), also known
|
|
|
|
as the public modulus.
|
|
|
|
*/
|
|
|
|
BigInteger n() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
The public key exponent
|
|
|
|
|
|
|
|
This value is the exponent chosen in the original key generator
|
|
|
|
step
|
|
|
|
*/
|
|
|
|
BigInteger e() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
\class RSAPrivateKey qca_publickey.h QtCrypto
|
|
|
|
|
|
|
|
RSA Private Key
|
2007-08-04 08:09:02 +00:00
|
|
|
|
|
|
|
\ingroup UserAPI
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
class QCA_EXPORT RSAPrivateKey : public PrivateKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Generate an empty RSA private key
|
|
|
|
*/
|
|
|
|
RSAPrivateKey();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Generate an RSA private key from specified parameters
|
|
|
|
|
|
|
|
\param n the public key value
|
|
|
|
\param e the public key exponent
|
|
|
|
\param p one of the two chosen primes
|
|
|
|
\param q the other of the two chosen primes
|
|
|
|
\param d inverse of the exponent, modulo (p-1)(q-1)
|
|
|
|
\param provider the provider to use, if a particular provider is
|
|
|
|
required
|
|
|
|
*/
|
|
|
|
RSAPrivateKey(const BigInteger &n, const BigInteger &e, const BigInteger &p, const BigInteger &q, const BigInteger &d, const QString &provider = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
The public key value
|
|
|
|
|
|
|
|
This value is the actual public key value (the product of p and q,
|
|
|
|
the random prime numbers used to generate the RSA key), also known
|
|
|
|
as the public modulus.
|
|
|
|
*/
|
|
|
|
BigInteger n() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
The public key exponent
|
|
|
|
|
|
|
|
This value is the exponent chosen in the original key generator
|
|
|
|
step
|
|
|
|
*/
|
|
|
|
BigInteger e() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
One of the two random primes used to generate the private key
|
|
|
|
*/
|
|
|
|
BigInteger p() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
The second of the two random primes used to generate the private
|
|
|
|
key
|
|
|
|
*/
|
|
|
|
BigInteger q() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
The inverse of the exponent, module (p-1)(q-1)
|
|
|
|
*/
|
|
|
|
BigInteger d() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
\class DSAPublicKey qca_publickey.h QtCrypto
|
|
|
|
|
|
|
|
Digital Signature %Algorithm Public Key
|
2007-08-04 08:09:02 +00:00
|
|
|
|
|
|
|
\ingroup UserAPI
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
class QCA_EXPORT DSAPublicKey : public PublicKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Create an empty DSA public key
|
|
|
|
*/
|
|
|
|
DSAPublicKey();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create a DSA public key
|
|
|
|
|
|
|
|
\param domain the discrete logarithm group to use
|
|
|
|
\param y the public random value
|
|
|
|
\param provider the provider to use, if a specific provider is
|
|
|
|
required
|
|
|
|
*/
|
|
|
|
DSAPublicKey(const DLGroup &domain, const BigInteger &y, const QString &provider = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create a DSA public key from a specified private key
|
|
|
|
|
|
|
|
\param k the DSA private key to use as the source
|
|
|
|
*/
|
|
|
|
DSAPublicKey(const DSAPrivateKey &k);
|
|
|
|
|
|
|
|
/**
|
|
|
|
The discrete logarithm group that is being used
|
|
|
|
*/
|
|
|
|
DLGroup domain() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
The public random value associated with this key
|
|
|
|
*/
|
|
|
|
BigInteger y() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
\class DSAPrivateKey qca_publickey.h QtCrypto
|
|
|
|
|
|
|
|
Digital Signature %Algorithm Private Key
|
2007-08-04 08:09:02 +00:00
|
|
|
|
|
|
|
\ingroup UserAPI
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
class QCA_EXPORT DSAPrivateKey : public PrivateKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Create an empty DSA private key
|
|
|
|
*/
|
|
|
|
DSAPrivateKey();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create a DSA public key
|
|
|
|
|
|
|
|
\param domain the discrete logarithm group to use
|
|
|
|
\param y the public random value
|
|
|
|
\param x the private random value
|
|
|
|
\param provider the provider to use, if a specific provider is
|
|
|
|
required
|
|
|
|
*/
|
|
|
|
DSAPrivateKey(const DLGroup &domain, const BigInteger &y, const BigInteger &x, const QString &provider = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
The discrete logarithm group that is being used
|
|
|
|
*/
|
|
|
|
DLGroup domain() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
the public random value
|
|
|
|
*/
|
|
|
|
BigInteger y() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
the private random value
|
|
|
|
*/
|
|
|
|
BigInteger x() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
\class DHPublicKey qca_publickey.h QtCrypto
|
|
|
|
|
|
|
|
Diffie-Hellman Public Key
|
2007-08-04 08:09:02 +00:00
|
|
|
|
|
|
|
\ingroup UserAPI
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
class QCA_EXPORT DHPublicKey : public PublicKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Create an empty Diffie-Hellman public key
|
|
|
|
*/
|
|
|
|
DHPublicKey();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create a Diffie-Hellman public key
|
|
|
|
|
|
|
|
\param domain the discrete logarithm group to use
|
|
|
|
\param y the public random value
|
|
|
|
\param provider the provider to use, if a specific provider is
|
|
|
|
required
|
|
|
|
*/
|
|
|
|
DHPublicKey(const DLGroup &domain, const BigInteger &y, const QString &provider = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create a Diffie-Hellman public key from a specified private key
|
|
|
|
|
|
|
|
\param k the Diffie-Hellman private key to use as the source
|
|
|
|
*/
|
|
|
|
DHPublicKey(const DHPrivateKey &k);
|
|
|
|
|
|
|
|
/**
|
|
|
|
The discrete logarithm group that is being used
|
|
|
|
*/
|
|
|
|
DLGroup domain() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
The public random value associated with this key
|
|
|
|
*/
|
|
|
|
BigInteger y() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
\class DHPrivateKey qca_publickey.h QtCrypto
|
|
|
|
|
|
|
|
Diffie-Hellman Private Key
|
2007-08-04 08:09:02 +00:00
|
|
|
|
|
|
|
\ingroup UserAPI
|
|
|
|
|
2007-06-01 23:22:53 +00:00
|
|
|
*/
|
|
|
|
class QCA_EXPORT DHPrivateKey : public PrivateKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Create an empty Diffie-Hellman private key
|
|
|
|
*/
|
|
|
|
DHPrivateKey();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create a Diffie-Hellman private key
|
|
|
|
|
|
|
|
\param domain the discrete logarithm group to use
|
|
|
|
\param y the public random value
|
|
|
|
\param x the private random value
|
|
|
|
\param provider the provider to use, if a particular provider is
|
|
|
|
required
|
|
|
|
*/
|
|
|
|
DHPrivateKey(const DLGroup &domain, const BigInteger &y, const BigInteger &x, const QString &provider = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
The discrete logarithm group that is being used
|
|
|
|
*/
|
|
|
|
DLGroup domain() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
The public random value associated with this key
|
|
|
|
*/
|
|
|
|
BigInteger y() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
The private random value associated with this key
|
|
|
|
*/
|
|
|
|
BigInteger x() const;
|
|
|
|
};
|
2007-07-30 23:40:24 +00:00
|
|
|
/*@}*/
|
2005-01-01 02:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|