Sailfish Crypto
API DocumentationKey Class
(Sailfish::Crypto::Key)An instance of a key which can be used for cryptographic operations. More...
Header: | #include <Crypto/key.h> |
Instantiated By: | Key |
Public Types
class | FilterData |
class | Identifier |
enum | Component { NoData, MetaData, PublicKeyData, PrivateKeyData, SecretKeyData } |
flags | Components |
enum | Origin { OriginUnknown, OriginImported, OriginDevice, OriginSecureDevice } |
enum | SerializationMode { LossySerializationMode, LosslessSerializationMode } |
Properties
|
|
Public Functions
Key() | |
Key(const Sailfish::Crypto::Key &other) | |
Key(const QString &name, const QString &collection, const QString &storagePluginName) | |
virtual | ~Key() |
Sailfish::Crypto::CryptoManager::Algorithm | algorithm() const |
QString | collectionName() const |
Sailfish::Crypto::Key::Components | componentConstraints() const |
QVector<QByteArray> | customParameters() const |
Sailfish::Crypto::Key::FilterData | filterData() const |
QString | filterData(const QString &field) const |
QStringList | filterDataFields() const |
bool | hasFilterData(const QString &field) |
Sailfish::Crypto::Key::Identifier | identifier() const |
QString | name() const |
Sailfish::Crypto::CryptoManager::Operations | operations() const |
Sailfish::Crypto::Key::Origin | origin() const |
QByteArray | privateKey() const |
QByteArray | publicKey() const |
QByteArray | secretKey() const |
void | setAlgorithm(Sailfish::Crypto::CryptoManager::Algorithm algorithm) |
void | setCollectionName(const QString &cname) |
void | setComponentConstraints(Sailfish::Crypto::Key::Components components) |
void | setCustomParameters(const QVector<QByteArray> ¶meters) |
void | setFilterData(const Sailfish::Crypto::Key::FilterData &data) |
void | setFilterData(const QString &field, const QString &value) |
void | setIdentifier(const Sailfish::Crypto::Key::Identifier &identifier) |
void | setName(const QString &name) |
void | setOperations(Sailfish::Crypto::CryptoManager::Operations operations) |
void | setOrigin(Sailfish::Crypto::Key::Origin origin) |
void | setPrivateKey(const QByteArray &key) |
void | setPublicKey(const QByteArray &key) |
void | setSecretKey(const QByteArray &key) |
void | setSize(int size) |
void | setStoragePluginName(const QString &pname) |
int | size() const |
QString | storagePluginName() const |
Sailfish::Crypto::Key & | operator=(const Sailfish::Crypto::Key &other) |
Static Public Members
Sailfish::Crypto::Key | deserialize(const QByteArray &data, bool *ok = nullptr) |
QByteArray | serialize(const Sailfish::Crypto::Key &key, SerializationMode serializationMode = LosslessSerializationMode) |
Detailed Description
An instance of a key which can be used for cryptographic operations.
The Key class encapsulates information about a cryptographic key, including metadata such as the cryptosystem algorithm the key is used with, the types of operations which may be performed with the key, and the parameters which are supported when performing operations with the key, as well as key data (private/public key data for asymmetric cryptosystems, and secret key data for symmetric cryptosystems).
In many cases, client applications need never know the key data, as the key can be generated and stored securely, and then used securely by name reference, without the key data ever entering the client application process address space.
See GenerateStoredKeyRequest for more information about securely generating a key which is stored by the system service, and see GenerateKeyRequest for more information about generating a key which is returned to the application.
Member Type Documentation
enum Key::Component
flags Key::Components
The Components type is a typedef for QFlags<Component>. It stores an OR combination of Component values.
enum Key::Origin
enum Key::SerializationMode
Property Documentation
algorithm : Sailfish::Crypto::CryptoManager::Algorithm
Access functions:
Sailfish::Crypto::CryptoManager::Algorithm | algorithm() const |
void | setAlgorithm(Sailfish::Crypto::CryptoManager::Algorithm algorithm) |
collectionName : QString
Access functions:
QString | collectionName() const |
void | setCollectionName(const QString &cname) |
componentConstraints : Sailfish::Crypto::Key::Components
Access functions:
Sailfish::Crypto::Key::Components | componentConstraints() const |
void | setComponentConstraints(Sailfish::Crypto::Key::Components components) |
customParameters : QVector<QByteArray>
Access functions:
QVector<QByteArray> | customParameters() const |
void | setCustomParameters(const QVector<QByteArray> ¶meters) |
filterDataFields : const QStringList
Access functions:
QStringList | filterDataFields() const |
name : QString
Access functions:
operations : Sailfish::Crypto::CryptoManager::Operations
Access functions:
Sailfish::Crypto::CryptoManager::Operations | operations() const |
void | setOperations(Sailfish::Crypto::CryptoManager::Operations operations) |
origin : Origin
Access functions:
Sailfish::Crypto::Key::Origin | origin() const |
void | setOrigin(Sailfish::Crypto::Key::Origin origin) |
privateKey : QByteArray
Access functions:
QByteArray | privateKey() const |
void | setPrivateKey(const QByteArray &key) |
publicKey : QByteArray
Access functions:
QByteArray | publicKey() const |
void | setPublicKey(const QByteArray &key) |
secretKey : QByteArray
Access functions:
QByteArray | secretKey() const |
void | setSecretKey(const QByteArray &key) |
size : int
Access functions:
storagePluginName : QString
Access functions:
QString | storagePluginName() const |
void | setStoragePluginName(const QString &pname) |
Member Function Documentation
Key::Key()
Constructs an empty key
Key::Key(const Sailfish::Crypto::Key &other)
Copy constructor.
Key::Key(const QString &name, const QString &collection, const QString &storagePluginName)
Constructs a key which references a stored key with the given name from the given collection in the storage plugin with the given storagePluginName.
A stored key is one which is stored securely by the Sailfish Crypto daemon, whose underlying secret data (e.g. private key or secret key data) will never be exposed to the client process.
[virtual]
Key::~Key()
Destroys the key
Sailfish::Crypto::CryptoManager::Algorithm Key::algorithm() const
Returns the cryptosystem algorithm this key is intended to be used with
Note: Getter function for property algorithm.
See also setAlgorithm().
QString Key::collectionName() const
Returns the collection name field from the identifier of the key
Note: Getter function for property collectionName.
See also setCollectionName().
Sailfish::Crypto::Key::Components Key::componentConstraints() const
Returns the types of key components which the client is allowed to retrieve after the key has been stored
Note: Getter function for property componentConstraints.
See also setComponentConstraints().
QVector<QByteArray> Key::customParameters() const
Returns the custom parameters associated with this key
Note: Getter function for property customParameters.
See also setCustomParameters().
[static]
Sailfish::Crypto::Key Key::deserialize(const QByteArray &data, bool *ok = nullptr)
Sailfish::Crypto::Key::FilterData Key::filterData() const
Returns the filter data associated with this key.
Other clients can use the filter data to find this key, if they have permission to access it. The filter data is a simple map of string field to string value.
See also setFilterData().
QString Key::filterData(const QString &field) const
Returns the filter data value for the given field.
QStringList Key::filterDataFields() const
Returns the fields (keys) of filter data associated with the secret
Note: Getter function for property filterDataFields.
bool Key::hasFilterData(const QString &field)
Returns true if the key has a filter data value specified for the given field.
Note that this function will always return true for the field "Type".
Sailfish::Crypto::Key::Identifier Key::identifier() const
Returns the identifier of the stored key which this key references
See also setIdentifier().
QString Key::name() const
Returns the name field from the identifier of the key
Note: Getter function for property name.
See also setName().
Sailfish::Crypto::CryptoManager::Operations Key::operations() const
Returns the set of operations which are supported for this key
Note: Getter function for property operations.
See also setOperations().
Sailfish::Crypto::Key::Origin Key::origin() const
Returns information about the origin of the key
Note: Getter function for property origin.
See also setOrigin().
QByteArray Key::privateKey() const
Returns the private key data associated with this key (asymmetric cryptosystems only)
Note: Getter function for property privateKey.
See also setPrivateKey().
QByteArray Key::publicKey() const
Returns the public key data associated with this key (asymmetric cryptosystems only)
Note: Getter function for property publicKey.
See also setPublicKey().
QByteArray Key::secretKey() const
Returns the private key data associated with this key (symmetric cryptosystems only)
Note: Getter function for property secretKey.
See also setSecretKey().
[static]
QByteArray Key::serialize(const Sailfish::Crypto::Key &key, SerializationMode serializationMode = LosslessSerializationMode)
void Key::setCollectionName(const QString &cname)
Sets the collection name field in the identifier of the key to cname
Note: Setter function for property collectionName.
See also collectionName().
void Key::setCustomParameters(const QVector<QByteArray> ¶meters)
Sets the custom parameters associated with this key to parameters.
Some cryptosystem providers (i.e. Sailfish Crypto API extension plugins) may require some custom parameters to be supplied when generating, storing or performing operations with keys.
In general, these parameters will be ignored unless the extension plugin requires them for some operation.
Note: Setter function for property customParameters.
See also customParameters().
void Key::setFilterData(const Sailfish::Crypto::Key::FilterData &data)
See also filterData().
void Key::setFilterData(const QString &field, const QString &value)
Sets filter data for the given field to the given value.
Note that the field "Type" will always have the value "CryptoKey" and this field value cannot be overwritten.
void Key::setIdentifier(const Sailfish::Crypto::Key::Identifier &identifier)
See also identifier().
void Key::setName(const QString &name)
Sets the name field in the identifier of the key to name
Note: Setter function for property name.
See also name().
void Key::setPrivateKey(const QByteArray &key)
Sets the private key data associated with this key to key
This field will be ignored if the algorithm specified for the key is that of a symmetric cryptosystem.
Note: Setter function for property privateKey.
See also privateKey().
void Key::setPublicKey(const QByteArray &key)
Sets the public key data associated with this key to key
Note: Setter function for property publicKey.
See also publicKey().
void Key::setSecretKey(const QByteArray &key)
Sets the secret key data associated with this key to key
This field will be ignored if the algorithm specified for the key is that of an asymmetric cryptosystem.
Note: Setter function for property secretKey.
See also secretKey().
void Key::setSize(int size)
Sets the security size, in bits, of the key to size
Clients should call this when generating a key (either via GenerateKeyRequest or GeneratedStoredKeyRequest).
Note that if the client also passes KeyDerivationParameters to such a request, the size specified here will be ignored, in favour of the output key size specified in those parameters.
If no valid symmetric key derivation parameters are passed to the request, then the crypto plugin will generate a key appropriate for the specified algorithm according to this size (for symmetric algorithms, this means that the plugin will usually generate random data of the appropriate size).
Note: Setter function for property size.
See also size().
void Key::setStoragePluginName(const QString &pname)
Sets the storage plugin name field in the identifier of the key to pname
Note: Setter function for property storagePluginName.
See also storagePluginName().
int Key::size() const
Returns the security size, in bits, of the key.
Note that this will NOT necessarily be the data size of any of the key fields, depending on the type of algorithm the key is designed to be used for.
For symmetric algorithm keys, the security size is generally also the data size (in bits) of the secret key.
For asymmetric keys, the security size is generally the size of the modulus (in the case of RSA keys) or the curve group size (in the case of ECC keys), and the actual data size of the private and public key data may be much larger (for example, the private key data for an RSA key could include modulus, public exponent, private exponent, prime factors, reduced modulo factors, and inverse factor modulo, in order to avoid having to recalculate those pieces of data at every use - which altogether adds up to a much larger data size than the security size).
As such, an RSA key with a security size of 2048 bits could have a data (storage) size of 1232 bytes (in PKCS#8 format).
Note: Getter function for property size.
See also setSize().
QString Key::storagePluginName() const
Returns the storage plugin name field from the identifier of the key
Note: Getter function for property storagePluginName.
See also setStoragePluginName().
Sailfish::Crypto::Key &Key::operator=(const Sailfish::Crypto::Key &other)
Copy-assignment operator.