Virgil Security Crypto library  1.8.2
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 randomization module used by encryption.
 
virtual ~VirgilCipherBase () throw ()
 Dispose used resources.
 
Recipent management
void addKeyRecipient (const VirgilByteArray &recipientId, const VirgilByteArray &publicKey)
 Add recipient defined with id and public key.
 
void removeKeyRecipient (const VirgilByteArray &recipientId)
 Remove recipient with given id. 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.
 
void removePasswordRecipient (const VirgilByteArray &pwd)
 Remove recipient with given password. More...
 
void removeAllRecipients ()
 Remove all recipients.
 
Custom parameters Access / Management

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.

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 ()
 
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::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&)
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.

Note
Call this method after encryption process.
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
recipientId- recipient's unique identifier.
Returns
true if recipient with given identifier exists, false - otherwise.
void virgil::crypto::VirgilCipherBase::removeKeyRecipient ( const VirgilByteArray &  recipientId)

Remove recipient with given id.

Note
If recipient with given id 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.

Note
Call this method before decryption process.
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: