33#ifndef QCA_PUBLICKEY_H
34#define QCA_PUBLICKEY_H
162QCA_EXPORT QByteArray
emsa3Encode(
const QString &hashName,
const QByteArray &digest,
int size = -1);
437 PKey(
const QString &type,
const QString &provider);
513 void assignToPublic(
PKey *dest)
const;
514 void assignToPrivate(
PKey *dest)
const;
697 const QByteArray &sig,
817 PublicKey(
const QString &type,
const QString &provider);
1059 const QString &provider = QString());
1082 const QString &provider = QString());
1109 const QString &provider = QString());
1263 friend class Private;
1350 const QString &provider = QString());
General superclass for an algorithm.
Definition qca_core.h:1164
Arbitrary precision integer.
Definition qca_tools.h:571
Diffie-Hellman Private Key.
Definition qca_publickey.h:1526
BigInteger y() const
The public random value associated with this key.
DHPrivateKey()
Create an empty Diffie-Hellman private key.
DLGroup domain() const
The discrete logarithm group that is being used.
BigInteger x() const
The private random value associated with this key.
DHPrivateKey(const DLGroup &domain, const BigInteger &y, const BigInteger &x, const QString &provider=QString())
Create a Diffie-Hellman private key.
Diffie-Hellman Public Key.
Definition qca_publickey.h:1482
DLGroup domain() const
The discrete logarithm group that is being used.
DHPublicKey(const DLGroup &domain, const BigInteger &y, const QString &provider=QString())
Create a Diffie-Hellman public key.
BigInteger y() const
The public random value associated with this key.
DHPublicKey(const DHPrivateKey &k)
Create a Diffie-Hellman public key from a specified private key.
DHPublicKey()
Create an empty Diffie-Hellman public key.
A discrete logarithm group.
Definition qca_publickey.h:172
DLGroup(const DLGroup &from)
Standard copy constructor.
BigInteger p() const
Provide the p component of the group.
DLGroup & operator=(const DLGroup &from)
Standard assignment operator.
static QList< DLGroupSet > supportedGroupSets(const QString &provider=QString())
Provide a list of the supported group sets.
bool isNull() const
Test if the group is empty.
DLGroup(const BigInteger &p, const BigInteger &g)
Construct a discrete logarithm group from raw parameters.
DLGroup(const BigInteger &p, const BigInteger &q, const BigInteger &g)
Construct a discrete logarithm group from raw parameters.
BigInteger g() const
Provide the g component of the group.
BigInteger q() const
Provide the q component of the group.
Digital Signature Algorithm Private Key.
Definition qca_publickey.h:1439
DLGroup domain() const
The discrete logarithm group that is being used.
BigInteger y() const
the public random value
DSAPrivateKey(const DLGroup &domain, const BigInteger &y, const BigInteger &x, const QString &provider=QString())
Create a DSA public key.
DSAPrivateKey()
Create an empty DSA private key.
BigInteger x() const
the private random value
Digital Signature Algorithm Public Key.
Definition qca_publickey.h:1395
DSAPublicKey()
Create an empty DSA public key.
DSAPublicKey(const DSAPrivateKey &k)
Create a DSA public key from a specified private key.
BigInteger y() const
The public random value associated with this key.
DLGroup domain() const
The discrete logarithm group that is being used.
DSAPublicKey(const DLGroup &domain, const BigInteger &y, const QString &provider=QString())
Create a DSA public key.
Class for generating asymmetric key pairs.
Definition qca_publickey.h:1138
PrivateKey createDH(const DLGroup &domain, const QString &provider=QString())
Generate a Diffie-Hellman key.
PrivateKey key() const
Return the last generated key.
DLGroup dlGroup() const
The current discrete logarithm group.
bool blockingEnabled() const
Test whether the key generator is set to operate in blocking mode, or not.
void finished()
Emitted when the key generation is complete.
PrivateKey createDSA(const DLGroup &domain, const QString &provider=QString())
Generate a DSA key.
PrivateKey createRSA(int bits, int exp=65537, const QString &provider=QString())
Generate an RSA key of the specified length.
DLGroup createDLGroup(QCA::DLGroupSet set, const QString &provider=QString())
Create a new discrete logarithm group.
bool isBusy() const
Test if the key generator is currently busy, or not.
KeyGenerator(QObject *parent=nullptr)
Create a new key generator.
void setBlockingEnabled(bool b)
Set whether the key generator is in blocking mode, nor not.
Array of bytes that may be optionally secured.
Definition qca_tools.h:91
General superclass for public (PublicKey) and private (PrivateKey) keys used with asymmetric encrypti...
Definition qca_publickey.h:251
void set(const PKey &k)
Set the key.
bool operator==(const PKey &a) const
test if two keys are equal
PKey(const PKey &from)
Standard copy constructor.
int bitSize() const
Report the number of bits in the key.
static QList< Type > supportedIOTypes(const QString &provider=QString())
Type type() const
Report the Type of key (eg RSA, DSA or Diffie Hellman)
DSAPublicKey toDSAPublicKey() const
Interpret this key as an DSAPublicKey.
RSAPrivateKey toRSAPrivateKey() const
Interpret this key as an RSAPrivateKey.
bool isDSA() const
Test if the key is a DSA key.
DHPrivateKey toDHPrivateKey() const
Interpret this key as a DHPrivateKey.
DHPublicKey toDHPublicKey() const
Interpret this key as an DHPublicKey.
bool isPublic() const
Test if the key is a public key.
bool isPrivate() const
Test if the key is a private key.
PKey()
Standard constructor.
PrivateKey toPrivateKey() const
Interpret this key as a PrivateKey.
bool isDH() const
Test if the key is a Diffie Hellman key.
PublicKey toPublicKey() const
Interpret this key as a PublicKey.
static QList< Type > supportedTypes(const QString &provider=QString())
bool operator!=(const PKey &a) const
test if two keys are not equal
bool isNull() const
Test if the key is null (empty)
RSAPublicKey toRSAPublicKey() const
Interpret this key as an RSAPublicKey.
bool canKeyAgree() const
Test if the key can be used for key agreement.
PKey & operator=(const PKey &from)
Standard assignment operator.
PKey(const QString &type, const QString &provider)
Create a key of the specified type.
DSAPrivateKey toDSAPrivateKey() const
Interpret this key as a DSAPrivateKey.
bool isRSA() const
Test if the key is an RSA key.
Type
Types of public key cryptography keys supported by QCA.
Definition qca_publickey.h:257
@ RSA
RSA key.
Definition qca_publickey.h:258
@ DSA
DSA key.
Definition qca_publickey.h:259
bool canExport() const
Test if the key data can be exported.
Generic private key.
Definition qca_publickey.h:833
static PrivateKey fromPEM(const QString &s, const SecureArray &passphrase=SecureArray(), ConvertResult *result=nullptr, const QString &provider=QString())
Import the key from Privacy Enhanced Mail (PEM) format.
PrivateKey(const QString &fileName, const SecureArray &passphrase=SecureArray())
Import a private key from a PEM representation in a file.
void update(const MemoryRegion &a)
Update the signature process.
bool toPEMFile(const QString &fileName, const SecureArray &passphrase=SecureArray(), PBEAlgorithm pbe=PBEDefault) const
Export the key in Privacy Enhanced Mail (PEM) format to a file.
static QList< PBEAlgorithm > supportedPBEAlgorithms(const QString &provider=QString())
List the supported Password Based Encryption Algorithms that can be used to protect the key.
bool decrypt(const SecureArray &in, SecureArray *out, EncryptionAlgorithm alg)
Decrypt the message.
SecureArray encrypt(const SecureArray &a, EncryptionAlgorithm alg)
Encrypt a message using a specified algorithm.
QByteArray signature()
The resulting signature.
RSAPrivateKey toRSA() const
Interpret / convert the key to an RSA key.
PrivateKey & operator=(const PrivateKey &from)
Assignment operator.
bool canDecrypt() const
Test if this key can be used for decryption.
DSAPrivateKey toDSA() const
Interpret / convert the key to a DSA key.
PrivateKey(const PrivateKey &from)
Copy constructor.
QByteArray signMessage(const MemoryRegion &a, SignatureAlgorithm alg, SignatureFormat format=DefaultFormat)
One step signature process.
PrivateKey(const QString &type, const QString &provider)
Create a new private key.
int maximumEncryptSize(EncryptionAlgorithm alg) const
The maximum message size that can be encrypted with a specified algorithm.
static PrivateKey fromPEMFile(const QString &fileName, const SecureArray &passphrase=SecureArray(), ConvertResult *result=nullptr, const QString &provider=QString())
Import the key in Privacy Enhanced Mail (PEM) format from a file.
SecureArray toDER(const SecureArray &passphrase=SecureArray(), PBEAlgorithm pbe=PBEDefault) const
Export the key in Distinguished Encoding Rules (DER) format.
void startSign(SignatureAlgorithm alg, SignatureFormat format=DefaultFormat)
Initialise the message signature process.
DHPrivateKey toDH() const
Interpret / convert the key to a Diffie-Hellman key.
PrivateKey()
Create an empty private key.
bool canEncrypt() const
Test if this key can be used for encryption.
SymmetricKey deriveKey(const PublicKey &theirs)
Derive a shared secret key from a public key.
static PrivateKey fromDER(const SecureArray &a, const SecureArray &passphrase=SecureArray(), ConvertResult *result=nullptr, const QString &provider=QString())
Import the key from Distinguished Encoding Rules (DER) format.
QString toPEM(const SecureArray &passphrase=SecureArray(), PBEAlgorithm pbe=PBEDefault) const
Export the key in Privacy Enhanced Mail (PEM) format.
bool canSign() const
Test if this key can be used for signing.
Generic public key.
Definition qca_publickey.h:529
PublicKey(const PublicKey &from)
Copy constructor.
void update(const MemoryRegion &a)
Update the signature verification process with more data.
DSAPublicKey toDSA() const
Convenience method to convert this key to a DSAPublicKey.
RSAPublicKey toRSA() const
Convenience method to convert this key to an RSAPublicKey.
bool verifyMessage(const MemoryRegion &a, const QByteArray &sig, SignatureAlgorithm alg, SignatureFormat format=DefaultFormat)
Single step message verification.
PublicKey(const QString &type, const QString &provider)
Create a new key of a specified type.
QByteArray toDER() const
Export the key in Distinguished Encoding Rules (DER) format.
bool canEncrypt() const
Test if this key can be used for encryption.
bool validSignature(const QByteArray &sig)
DHPublicKey toDH() const
Convenience method to convert this key to a DHPublicKey.
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())
bool decrypt(const SecureArray &in, SecureArray *out, EncryptionAlgorithm alg)
Decrypt the message.
bool toPEMFile(const QString &fileName) const
Export the key in Privacy Enhanced Mail (PEM) to a file.
void startVerify(SignatureAlgorithm alg, SignatureFormat format=DefaultFormat)
Initialise the signature verification process.
static PublicKey fromDER(const QByteArray &a, ConvertResult *result=nullptr, const QString &provider=QString())
PublicKey(const PrivateKey &k)
Create a public key based on a specified private key.
bool canVerify() const
Test if the key can be used for verifying signatures.
int maximumEncryptSize(EncryptionAlgorithm alg) const
The maximum message size that can be encrypted with a specified algorithm.
PublicKey & operator=(const PublicKey &from)
Assignment operator.
PublicKey(const QString &fileName)
Import a public key from a PEM representation in a file.
bool canDecrypt() const
Test if this key can be used for decryption.
PublicKey()
Create an empty (null) public key.
SecureArray encrypt(const SecureArray &a, EncryptionAlgorithm alg)
Encrypt a message using a specified algorithm.
QString toPEM() const
Export the key in Privacy Enhanced Mail (PEM) format.
RSA Private Key.
Definition qca_publickey.h:1327
RSAPrivateKey()
Generate an empty RSA private key.
BigInteger q() const
The second of the two random primes used to generate the private key.
BigInteger d() const
The inverse of the exponent, module (p-1)(q-1)
BigInteger n() const
The public key value.
BigInteger e() const
The public key exponent.
BigInteger p() const
One of the two random primes used to generate the private key.
RSAPrivateKey(const BigInteger &n, const BigInteger &e, const BigInteger &p, const BigInteger &q, const BigInteger &d, const QString &provider=QString())
Generate an RSA private key from specified parameters.
RSA Public Key.
Definition qca_publickey.h:1276
RSAPublicKey()
Generate an empty RSA public key.
RSAPublicKey(const BigInteger &n, const BigInteger &e, const QString &provider=QString())
Generate an RSA public key from specified parameters.
RSAPublicKey(const RSAPrivateKey &k)
Extract the public key components from an RSA private key.
BigInteger n() const
The public key value.
BigInteger e() const
The public key exponent.
Secure array of bytes.
Definition qca_tools.h:317
Container for keys for symmetric encryption algorithms.
Definition qca_core.h:1264
QCA - the Qt Cryptographic Architecture.
Definition qca_basic.h:41
DLGroupSet
Well known discrete logarithm group sets.
Definition qca_publickey.h:135
@ DSA_512
512 bit group, for compatibility with JCE
Definition qca_publickey.h:136
@ DSA_768
768 bit group, for compatibility with JCE
Definition qca_publickey.h:137
@ IETF_1536
1536-bit MODP Group ("group 5") from RFC3526 Section 2.
Definition qca_publickey.h:141
@ IETF_3072
3072-bit MODP Group ("group 15") from RFC3526 Section 4.
Definition qca_publickey.h:143
@ IETF_1024
Group 2 from RFC 2412, Section E.2.
Definition qca_publickey.h:140
@ DSA_1024
1024 bit group, for compatibility with JCE
Definition qca_publickey.h:138
@ IETF_8192
8192-bit MODP Group ("group 18") from RFC3526 Section 7.
Definition qca_publickey.h:146
@ IETF_6144
6144-bit MODP Group ("group 17") from RFC3526 Section 6.
Definition qca_publickey.h:145
@ IETF_768
Group 1 from RFC 2412, Section E.1.
Definition qca_publickey.h:139
@ IETF_4096
4096-bit MODP Group ("group 16") from RFC3526 Section 5.
Definition qca_publickey.h:144
@ IETF_2048
2048-bit MODP Group ("group 14") from RFC3526 Section 3.
Definition qca_publickey.h:142
EncryptionAlgorithm
Encryption algorithms.
Definition qca_publickey.h:55
@ EME_PKCS1v15
Block type 2 (PKCS#1, Version 1.5)
Definition qca_publickey.h:56
@ EME_PKCS1v15_SSL
PKCS#1, Version 1.5 with an SSL-specific modification.
Definition qca_publickey.h:58
@ EME_NO_PADDING
Raw RSA encryption.
Definition qca_publickey.h:59
@ EME_PKCS1_OAEP
Optimal asymmetric encryption padding (PKCS#1, Version 2.0)
Definition qca_publickey.h:57
PBEAlgorithm
Password-based encryption.
Definition qca_publickey.h:103
@ PBES2_AES192_SHA1
PKCS#5 v2.0 AES-192/CBC,SHA1.
Definition qca_publickey.h:108
@ PBES2_DES_SHA1
PKCS#5 v2.0 DES/CBC,SHA1.
Definition qca_publickey.h:105
@ PBEDefault
Use modern default (same as PBES2_TripleDES_SHA1)
Definition qca_publickey.h:104
@ PBES2_TripleDES_SHA1
PKCS#5 v2.0 TripleDES/CBC,SHA1.
Definition qca_publickey.h:106
@ PBES2_AES128_SHA1
PKCS#5 v2.0 AES-128/CBC,SHA1.
Definition qca_publickey.h:107
@ PBES2_AES256_SHA1
PKCS#5 v2.0 AES-256/CBC,SHA1.
Definition qca_publickey.h:109
ConvertResult
Return value from a format conversion.
Definition qca_publickey.h:119
@ ErrorFile
Failure because of incorrect file.
Definition qca_publickey.h:123
@ ErrorPassphrase
Failure because of incorrect passphrase.
Definition qca_publickey.h:122
@ ConvertGood
Conversion succeeded, results should be valid.
Definition qca_publickey.h:120
@ ErrorDecode
General failure in the decode stage.
Definition qca_publickey.h:121
QCA_EXPORT QByteArray emsa3Encode(const QString &hashName, const QByteArray &digest, int size=-1)
Encode a hash result in EMSA3 (PKCS#1) format.
SignatureAlgorithm
Signature algorithm variants.
Definition qca_publickey.h:74
@ EMSA3_RIPEMD160
RIPEMD160, with EMSA3 (ie PKCS#1 Version 1.5) encoding.
Definition qca_publickey.h:80
@ EMSA3_Raw
EMSA3 without computing a message digest or a DigestInfo encoding (identical to PKCS#11's CKM_RSA_PKC...
Definition qca_publickey.h:81
@ EMSA3_SHA1
SHA1, with EMSA3 (ie PKCS#1 Version 1.5) encoding.
Definition qca_publickey.h:77
@ EMSA1_SHA1
SHA1, with EMSA1 (IEEE1363-2000) encoding (this is the usual DSA algorithm - FIPS186)
Definition qca_publickey.h:76
@ EMSA3_SHA512
SHA512, with EMSA3 (ie PKCS#1 Version 1.5) encoding.
Definition qca_publickey.h:86
@ EMSA3_SHA256
SHA256, with EMSA3 (ie PKCS#1 Version 1.5) encoding.
Definition qca_publickey.h:84
@ EMSA3_SHA224
SHA224, with EMSA3 (ie PKCS#1 Version 1.5) encoding.
Definition qca_publickey.h:83
@ EMSA3_SHA384
SHA384, with EMSA3 (ie PKCS#1 Version 1.5) encoding.
Definition qca_publickey.h:85
@ EMSA3_MD2
MD2, with EMSA3 (ie PKCS#1 Version 1.5) encoding.
Definition qca_publickey.h:79
@ EMSA3_MD5
MD5, with EMSA3 (ie PKCS#1 Version 1.5) encoding (this is the usual RSA algorithm)
Definition qca_publickey.h:78
@ SignatureUnknown
Unknown signing algorithm.
Definition qca_publickey.h:75
SignatureFormat
Signature formats (DSA only)
Definition qca_publickey.h:93
@ DERSequence
Signature wrapped in DER formatting (OpenSSL/Java)
Definition qca_publickey.h:96
@ DefaultFormat
For DSA, this is the same as IEEE_1363.
Definition qca_publickey.h:94
@ IEEE_1363
40-byte format from IEEE 1363 (Botan/.NET)
Definition qca_publickey.h:95
Header file for core QCA infrastructure.