Virgil Security Crypto library  2.6.3
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::VirgilSeqCipher virgil::crypto::VirgilStreamCipher

Public Member Functions

 VirgilCipherBase ()
 Initialize submodules.
 
Recipient 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 filterAndSetupContentInfo (const VirgilByteArray &encryptedData, bool isLastChunk)
 Extract content info from the encrypted data and setup it. More...
 
void initEncryption ()
 Configures symmetric cipher for encryption. More...
 
void initDecryptionWithPassword (const VirgilByteArray &pwd)
 Stores recipient's password that is used for cipher's key decryption when content becomes available. More...
 
void initDecryptionWithKey (const VirgilByteArray &recipientId, const VirgilByteArray &privateKey, const VirgilByteArray &privateKeyPassword)
 Stores recipient's information that is used for cipher's key decryption when content becomes available. More...
 
bool isInited () const
 
bool isReadyForEncryption () const
 
bool isReadyForDecryption () const
 
virgil::crypto::foundation::VirgilSymmetricCiphergetSymmetricCipher ()
 Return symmetric cipher configure by one of the methods: initEncryption(), initDecryptionWithPassword(), initDecryptionWithKey.
 
void buildContentInfo ()
 Build VirgilContentInfo object. More...
 
void clear ()
 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
 Return content 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::clear ( )
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 getSymmetricCipher(), 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::filterAndSetupContentInfo ( const VirgilByteArray encryptedData,
bool  isLastChunk 
)
protected

Extract content info from the encrypted data and setup it.

This function should be used always to filter input encrypted data.

Parameters
encryptedData- data that was encrypted.
isLastChunk- tell filter that given data is the last one. return Encrypted data that is follows content info, if content info was fully extracted, otherwise - empty data.
VirgilByteArray virgil::crypto::VirgilCipherBase::getContentInfo ( ) const

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.
void virgil::crypto::VirgilCipherBase::initDecryptionWithKey ( const VirgilByteArray recipientId,
const VirgilByteArray privateKey,
const VirgilByteArray privateKeyPassword 
)
protected

Stores recipient's information that is used for cipher's key decryption when content becomes available.

Parameters
recipientId- recipient's id.
privateKey- recipient's private key.
privateKeyPassword- recipient's private key password.
void virgil::crypto::VirgilCipherBase::initDecryptionWithPassword ( const VirgilByteArray pwd)
protected

Stores recipient's password that is used for cipher's key decryption when content becomes available.

Parameters
pwd- recipient's password.
void virgil::crypto::VirgilCipherBase::initEncryption ( )
protected

Configures symmetric cipher for encryption.

Note
cipher's key randomly generated.
cipher's input vector is randomly generated.
bool virgil::crypto::VirgilCipherBase::isInited ( ) const
protected

Return true if one one of the init function was called.

bool virgil::crypto::VirgilCipherBase::isReadyForDecryption ( ) const
protected

Return true if underlying symmetric cipher is properly configured for decryption.

bool virgil::crypto::VirgilCipherBase::isReadyForEncryption ( ) const
protected

Return true if underlying symmetric cipher is properly configured for encryption.

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.

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