Virgil Security Crypto library  2.0.7
Public Member Functions | Protected Member Functions | List of all members
virgil::crypto::VirgilCipherBase Class Reference

This class provides configuration methods to all Virgil*Cipher classes. More...

#include <VirgilCipherBase.h>

Inheritance diagram for virgil::crypto::VirgilCipherBase:
virgil::crypto::VirgilChunkCipher virgil::crypto::VirgilCipher virgil::crypto::VirgilStreamCipher

Public Member Functions

 VirgilCipherBase ()
 Initialize submodules.
 
Recipent management
void addKeyRecipient (const VirgilByteArray &recipientId, const VirgilByteArray &publicKey)
 Add recipient defined with id and public key. More...
 
void removeKeyRecipient (const VirgilByteArray &recipientId)
 Remove recipient with given identifier. More...
 
bool keyRecipientExists (const VirgilByteArray &recipientId) const
 Check whether recipient with given identifier exists. More...
 
void addPasswordRecipient (const VirgilByteArray &pwd)
 Add recipient defined with password. More...
 
void removePasswordRecipient (const VirgilByteArray &pwd)
 Remove recipient with given password. More...
 
bool passwordRecipientExists (const VirgilByteArray &password) const
 Check whether recipient with given password exists. More...
 
void removeAllRecipients ()
 Remove all recipients.
 
Custom parameters Access / Management

Custom parameters is a structure that contains additional user defined information about encrypted data.

Note
This information is stored as part of the content info in unencrypted format.
VirgilCustomParamscustomParams ()
 Provide access to the object that handles custom parameters. More...
 
const VirgilCustomParamscustomParams () const
 Provide readonly access to the object that handles custom parameters. More...
 

Static Public Member Functions

Helpers to create shared key with Diffie–Hellman algorithms
static VirgilByteArray computeShared (const VirgilByteArray &publicKey, const VirgilByteArray &privateKey, const VirgilByteArray &privateKeyPassword=VirgilByteArray())
 Compute shared secret key on a given keys. More...
 

Protected Member Functions

VirgilByteArray tryReadContentInfo (const VirgilByteArray &encryptedData)
 Make attempt to read content info from the encrypted data. More...
 
virgil::crypto::foundation::VirgilSymmetricCipherinitEncryption ()
 Configures symmetric cipher for encryption. More...
 
virgil::crypto::foundation::VirgilSymmetricCipherinitDecryption (const VirgilByteArray &encryptedDataInfo, const VirgilByteArray &recipientId, const VirgilByteArray &privateKey, const VirgilByteArray &privateKeyPassword=VirgilByteArray())
 Configures symmetric cipher for encryption. More...
 
virgil::crypto::foundation::VirgilSymmetricCipherinitDecryptionWithPassword (const VirgilByteArray &pwd)
 Configures symmetric cipher for decryption based on the recipient's password. More...
 
virgil::crypto::foundation::VirgilSymmetricCipherinitDecryptionWithKey (const VirgilByteArray &recipientId, const VirgilByteArray &privateKey, const VirgilByteArray &privateKeyPassword)
 Configures symmetric cipher for decryption based on the recipient's id and private key. More...
 
virgil::crypto::foundation::VirgilSymmetricCiphergetSymmetricCipher ()
 Return symmetric cipher configure by one of the methods: initEncryption(), initDecryptionWithPassword(), initDecryptionWithKey.
 
void buildContentInfo ()
 Build VirgilContentInfo object. More...
 
void clearCipherInfo ()
 Clear all information related to the cipher. More...
 

Content Info Access / Management

Content info is a structure that contains all necessary information for future decription in secure form.

VirgilByteArray getContentInfo () const
 Returns encrypted data info. More...
 
void setContentInfo (const VirgilByteArray &contentInfo)
 Create content info object from ASN.1 structure. More...
 
static size_t defineContentInfoSize (const VirgilByteArray &data)
 Read content info size as part of the data. More...
 

Detailed Description

This class provides configuration methods to all Virgil*Cipher classes.

Member Function Documentation

void virgil::crypto::VirgilCipherBase::addKeyRecipient ( const VirgilByteArray recipientId,
const VirgilByteArray publicKey 
)

Add recipient defined with id and public key.

Parameters
recipientIdRecipient's unique identifier, MUST not be empty.
publicKeyRecipient's public key, MUST not be empty.
Exceptions
VirgilCryptoExceptionwith VirgilCryptoErrorCode::InvalidArgument, if invalid arguments are given.
void virgil::crypto::VirgilCipherBase::addPasswordRecipient ( const VirgilByteArray pwd)

Add recipient defined with password.

Use it for password based encryption.

Parameters
pwdRecipient's password, MUST not be empty.
Exceptions
VirgilCryptoExceptionwith VirgilCryptoErrorCode::InvalidArgument, if empty argument are given.
void virgil::crypto::VirgilCipherBase::buildContentInfo ( )
protected

Build VirgilContentInfo object.

This method SHOULD be called after encryption process is finished.

Note
This method SHOULD be called after encryption process is finished.
void virgil::crypto::VirgilCipherBase::clearCipherInfo ( )
protected

Clear all information related to the cipher.

Clear symmetric cipher and correspond internal states.

Note
This method SHOULD be called after encryption or decryption process is finished.
You CAN not use symmetric cipher returned by the method () , after this method call.
static VirgilByteArray virgil::crypto::VirgilCipherBase::computeShared ( const VirgilByteArray publicKey,
const VirgilByteArray privateKey,
const VirgilByteArray privateKeyPassword = VirgilByteArray() 
)
static

Compute shared secret key on a given keys.

Parameters
publicKey- alice public key.
privateKey- bob private key.
privateKeyPassword- bob private key password.
Exceptions
VirgilCryptoException- if keys are invalid or keys are not compatible.
Warning
Keys SHOULD be of the identical type, i.e. both of type Curve25519.
See also
VirgilKeyPair::generate(const VirgilKeyPair&, const VirgilByteArray&, const VirgilByteArray&)
VirgilCustomParams& virgil::crypto::VirgilCipherBase::customParams ( )

Provide access to the object that handles custom parameters.

Note
Use this method to add custom parameters to the content info object.
Use this method before encryption process.
const VirgilCustomParams& virgil::crypto::VirgilCipherBase::customParams ( ) const

Provide readonly access to the object that handles custom parameters.

Note
Use this method to read custom parameters from the content info object.
static size_t virgil::crypto::VirgilCipherBase::defineContentInfoSize ( const VirgilByteArray data)
static

Read content info size as part of the data.

Returns
Size of the content info if it is exist as part of the data, 0 - otherwise.
VirgilByteArray virgil::crypto::VirgilCipherBase::getContentInfo ( ) const

Returns encrypted data info.

Return content info.

Return Virgil Security Cryptogram, that contains public algorithm parameters that was used for encryption.

Note
Call this method after encryption process.
Exceptions
VirgilCryptoExceptionwith VirgilCryptoErrorCode::InvalidOperation, if this function is used before any encryption operation.
virgil::crypto::foundation::VirgilSymmetricCipher& virgil::crypto::VirgilCipherBase::initDecryption ( const VirgilByteArray encryptedDataInfo,
const VirgilByteArray recipientId,
const VirgilByteArray privateKey,
const VirgilByteArray privateKeyPassword = VirgilByteArray() 
)
protected

Configures symmetric cipher for encryption.

Configures symmetric cipher for decryption.

Parameters
encryptedDataInfo- serialized encrypted data info.
recipientId- id that corresponds to the user's private key.
privateKey- user's private key.
privateKeyPassword- user's private key password.
Returns
Configured cipher.
virgil::crypto::foundation::VirgilSymmetricCipher& virgil::crypto::VirgilCipherBase::initDecryptionWithKey ( const VirgilByteArray recipientId,
const VirgilByteArray privateKey,
const VirgilByteArray privateKeyPassword 
)
protected

Configures symmetric cipher for decryption based on the recipient's id and private key.

Parameters
recipientId- recipient's id.
privateKey- recipient's private key.
privateKeyPassword- recipient's private key password.
Returns
Configured cipher.
virgil::crypto::foundation::VirgilSymmetricCipher& virgil::crypto::VirgilCipherBase::initDecryptionWithPassword ( const VirgilByteArray pwd)
protected

Configures symmetric cipher for decryption based on the recipient's password.

Parameters
pwd- recipient's password.
Returns
Configured cipher.
virgil::crypto::foundation::VirgilSymmetricCipher& virgil::crypto::VirgilCipherBase::initEncryption ( )
protected

Configures symmetric cipher for encryption.

Returns
Configured cipher.
Note
cipher's key randomly generated.
cipher's input vector is randomly generated.
bool virgil::crypto::VirgilCipherBase::keyRecipientExists ( const VirgilByteArray recipientId) const

Check whether recipient with given identifier exists.

Search order:

  1. Local structures - useful when cipher is used for encryption.
  2. ContentInfo structure - useful when cipher is used for decryption.
Parameters
recipientIdRecipient's unique identifier.
Returns
true if recipient with given identifier exists, false - otherwise.
bool virgil::crypto::VirgilCipherBase::passwordRecipientExists ( const VirgilByteArray password) const

Check whether recipient with given password exists.

Search order:

  1. Local structures - useful when cipher is used for encryption.
Parameters
passwordRecipient's unique identifier.
Returns
true if recipient with given password exists, false - otherwise.
void virgil::crypto::VirgilCipherBase::removeKeyRecipient ( const VirgilByteArray recipientId)

Remove recipient with given identifier.

Parameters
recipientIdRecipient's unique identifier.
Note
If recipient with given identifier is absent - do nothing.
void virgil::crypto::VirgilCipherBase::removePasswordRecipient ( const VirgilByteArray pwd)

Remove recipient with given password.

Note
If recipient with given password is absent - do nothing.
void virgil::crypto::VirgilCipherBase::setContentInfo ( const VirgilByteArray contentInfo)

Create content info object from ASN.1 structure.

Parameters
contentInfoVirgil Security Cryptogram.
Note
Call this method before decryption process.
Exceptions
VirgilCryptoExceptionwith VirgilCryptoErrorCode::InvalidFormat, if content info can not be parsed.
VirgilByteArray virgil::crypto::VirgilCipherBase::tryReadContentInfo ( const VirgilByteArray encryptedData)
protected

Make attempt to read content info from the encrypted data.

Payload content info if was detected in the encrypted data.

Parameters
encryptedData- data that was encrypted. return Encrypted data without content info.

The documentation for this class was generated from the following file: