Virgil Security Crypto library  2.1.2
Public Types | List of all members
virgil::crypto::foundation::VirgilPBE Class Reference

Provides Password-Based Cryptography. Now PKCS#5 and PKCS#12 are partially supported. More...

#include <VirgilPBE.h>

Inheritance diagram for virgil::crypto::foundation::VirgilPBE:
virgil::crypto::foundation::asn1::VirgilAsn1Compatible

Public Types

enum  Algorithm { Algorithm::PKCS5, Algorithm::PKCS12 }
 Enumerates possible Password Based Encryption algorithms. More...
 

Public Member Functions

Constructor / Destructor
 VirgilPBE ()
 Create object with undefined algorithm. More...
 
 VirgilPBE (Algorithm alg, const VirgilByteArray &salt, size_t iterationCount=kIterationCountMin)
 reate object with specific algorithm type. More...
 
Encryption / Decryption
virgil::crypto::VirgilByteArray encrypt (const virgil::crypto::VirgilByteArray &data, const virgil::crypto::VirgilByteArray &pwd) const
 Encrypt data with given password. More...
 
virgil::crypto::VirgilByteArray decrypt (const virgil::crypto::VirgilByteArray &data, const virgil::crypto::VirgilByteArray &pwd) const
 Decrypt data with given password. More...
 
VirgilAsn1Compatible implementation
Marshalling format:
PBE ::= AlgorithmIdentifier {{ PBEAlgorithms }}
PBEAlgorithms AlgorithmIdentifier ::= {
{ OID id-PBES2 PARMS PBES2-params } |
{ OID pkcs-12PbeId PARMS pkcs-12PbeParams }
}
size_t asn1Write (asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const override
 Write object state to the writer. More...
 
void asn1Read (asn1::VirgilAsn1Reader &asn1Reader) override
 Read object state from the reader. More...
 
- Public Member Functions inherited from virgil::crypto::foundation::asn1::VirgilAsn1Compatible
virgil::crypto::VirgilByteArray toAsn1 () const
 Save object state to the ASN.1 structure.
 
void fromAsn1 (const virgil::crypto::VirgilByteArray &asn1)
 Restore object state from the ASN.1 structure.
 
virtual ~VirgilAsn1Compatible () noexcept
 Polymorphic destructor.
 

Static Public Attributes

Constants
static constexpr size_t kIterationCountMin = 1024
 Recommended iteration count that is used for key derivation.
 

Additional Inherited Members

- Protected Member Functions inherited from virgil::crypto::foundation::asn1::VirgilAsn1Compatible
virtual void checkRequiredField (const VirgilByteArray &param) const
 If given parameter is empty exception will be thrown. More...
 

Detailed Description

Provides Password-Based Cryptography. Now PKCS#5 and PKCS#12 are partially supported.

Member Enumeration Documentation

Enumerates possible Password Based Encryption algorithms.

Enumerator
PKCS5 

PBE Algorithm: from the standard PKCS#5.

PKCS12 

PBE Algorithm: from the standard PKCS#12.

Constructor & Destructor Documentation

virgil::crypto::foundation::VirgilPBE::VirgilPBE ( )

Create object with undefined algorithm.

Warning
SHOULD be used in conjunction with VirgilAsn1Compatible interface, i.e. VirgilPBE pbe; pbe.fromAsn1(asn1);
virgil::crypto::foundation::VirgilPBE::VirgilPBE ( Algorithm  alg,
const VirgilByteArray salt,
size_t  iterationCount = kIterationCountMin 
)

reate object with specific algorithm type.

Parameters
algSpecific PBE algorithm.
saltSalt, it is recommended to use random value for security reasons.
iterationCountIteration count for the key derivation, it is recommended to use random value for security reasons.

Member Function Documentation

void virgil::crypto::foundation::VirgilPBE::asn1Read ( asn1::VirgilAsn1Reader asn1Reader)
overridevirtual

Read object state from the reader.

Parameters
asn1Readerreader payloaded with ASN.1 to be read.

Implements virgil::crypto::foundation::asn1::VirgilAsn1Compatible.

size_t virgil::crypto::foundation::VirgilPBE::asn1Write ( asn1::VirgilAsn1Writer asn1Writer,
size_t  childWrittenBytes = 0 
) const
overridevirtual

Write object state to the writer.

Parameters
asn1Writerwriter that should be payloaded by subclasses.
childWrittenBytescount of bytes that was written by subclasses.
Returns
Writen bytes count.

Implements virgil::crypto::foundation::asn1::VirgilAsn1Compatible.

virgil::crypto::VirgilByteArray virgil::crypto::foundation::VirgilPBE::decrypt ( const virgil::crypto::VirgilByteArray data,
const virgil::crypto::VirgilByteArray pwd 
) const

Decrypt data with given password.

Parameters
data- data to decrypt.
pwd- password to use for decryption (max length is 31 byte).
Returns
Decrypted data.
virgil::crypto::VirgilByteArray virgil::crypto::foundation::VirgilPBE::encrypt ( const virgil::crypto::VirgilByteArray data,
const virgil::crypto::VirgilByteArray pwd 
) const

Encrypt data with given password.

Parameters
data- data to encrypt.
pwd- password to use for encryption (max length is 31 byte).
Returns
Encrypted data.

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