YAPET::Crypt Class Reference

Encrypts and decrypts data. More...

#include <crypt.h>

List of all members.

Public Member Functions

 Crypt (const Crypt &c)
 Crypt (const Key &k) throw (YAPETException)
 Constructor.
template<class T>
Record< T > * decrypt (const BDBuffer &data) throw (YAPETException, YAPETEncryptionException)
 Decrypts data.
template<class T>
BDBufferencrypt (const Record< T > &data) throw (YAPETException, YAPETEncryptionException)
 Encrypts data.
uint32_t getIVLength () const
 Returns the length of the initialization vector.
uint32_t getKeyLength () const
 Returns the length of the key.
const Cryptoperator= (const Crypt &c)
 ~Crypt ()

Private Attributes

const EVP_CIPHER * cipher
 Pointer to the cipher used for encryption/decryption.
uint32_t iv_length
 Length of the initialization vector.
Key key
 the key used for encryption/decryption
uint32_t key_length
 Length of the encryption/decryption key.


Detailed Description

This class encrypts and decrypts data using the key provided by Key.

Encrypted data is returned in BDBuffer. Decrypted data is returned as a struct as defined in structs.h using the template Record.

Currently, the blowfish algorithm in CBC mode from the openssl library is used for encryption and decryption. The class itself does not have any encryption/decryption logic.

See also:
Key, BDBuffer, Record

Definition at line 57 of file crypt.h.


Constructor & Destructor Documentation

Crypt::Crypt ( const Key k  )  throw (YAPETException)

Initializes the class with the given key, which is used for encryption and decryption.

The constructor tries to set the key length of the cipher used to the length of the key provided. If this fails, a YAPETException is thrown.

Parameters:
k the key used for encryption/decryption.
Exceptions:
YAPETException in case the key length of the cipher cannot be set to the length of the key provided.

Definition at line 37 of file crypt.cc.

Crypt::Crypt ( const Crypt c  ) 

Definition at line 67 of file crypt.cc.

YAPET::Crypt::~Crypt (  )  [inline]

Definition at line 93 of file crypt.h.


Member Function Documentation

template<class T>
Record<T>* YAPET::Crypt::decrypt ( const BDBuffer data  )  throw (YAPETException, YAPETEncryptionException) [inline]

Decrypts the data supplied in the BDBuffer. It returns the decrypted data as a Record of the specified type.

The Record has to be freed by the caller.

Parameters:
data the BDBuffer to decrypt.
Returns:
pointer to a Record of the specified type, holding the decrypted data. The caller is responsible for freeing the memory occupied by the object returned.
Exceptions:
YAPETException 
YAPETEncryptionException 
See also:
Record, BDBuffer

Definition at line 216 of file crypt.h.

References YAPET::BDBuffer::at(), cipher, YAPET::Key::getIVec(), iv_length, YAPET::Key::ivec_size(), key, YAPET::BDBuffer::resize(), YAPET::BDBuffer::size(), and YAPET::Key::size().

Referenced by YAPET::File::getMasterPWSet(), YAPET::File::initFile(), YAPET::PartDec::PartDec(), PasswordRecord::refresh(), YAPET::File::setNewKey(), and YAPET::File::validateKey().

template<class T>
BDBuffer* YAPET::Crypt::encrypt ( const Record< T > &  data  )  throw (YAPETException, YAPETEncryptionException) [inline]

Encrypts the data provided in data which has to be an instance of the Record template.

The encrypted data is returned as BDBuffer with the size set exactly to the size of the encrypted data. The memory occupied by this object has to be freed by the caller.

Parameters:
data the data to be encrypted.
Returns:
pointer to a BDBuffer holding the encrypted data. The caller is responsible for freeing the memory occupied by the object returned.
Exceptions:
YAPETException 
YAPETEncryptionException 
See also:
Record, BDBuffer

Definition at line 139 of file crypt.h.

References YAPET::BDBuffer::at(), cipher, YAPET::Key::getIVec(), iv_length, YAPET::Key::ivec_size(), key, YAPET::BDBuffer::resize(), YAPET::BDBuffer::size(), and YAPET::Key::size().

Referenced by YAPET::File::setNewKey(), YAPET::PartDec::setRecord(), and YAPET::File::writeHeader().

uint32_t YAPET::Crypt::getIVLength (  )  const [inline]

Returns the length in bytes of the initialization vector the cipher algorithm expects

Returns:
the length of the initialization vector in bytes.

Definition at line 104 of file crypt.h.

References iv_length.

uint32_t YAPET::Crypt::getKeyLength (  )  const [inline]

Returns the length in bytes of the key the cipher algorithm expects.

Returns:
the length of the key in bytes.

Definition at line 113 of file crypt.h.

References key_length.

const Crypt & Crypt::operator= ( const Crypt c  ) 

Definition at line 74 of file crypt.cc.

References cipher, iv_length, key, and key_length.


Member Data Documentation

const EVP_CIPHER* YAPET::Crypt::cipher [private]

Pointer the cipher implemented in the openssl library. Currently, blowfish is used for encryption/decryption.

Definition at line 67 of file crypt.h.

Referenced by decrypt(), encrypt(), and operator=().

uint32_t YAPET::Crypt::iv_length [private]

Length of the initialization vector as expected by the cipher implementation in bytes.

Definition at line 74 of file crypt.h.

Referenced by decrypt(), encrypt(), getIVLength(), and operator=().

Key YAPET::Crypt::key [private]

The key used for encryption/decryption.

Definition at line 87 of file crypt.h.

Referenced by decrypt(), encrypt(), and operator=().

uint32_t YAPET::Crypt::key_length [private]

Length of the encryption/decryption key as expected by the cipher implementation in bytes.

Definition at line 81 of file crypt.h.

Referenced by getKeyLength(), and operator=().


The documentation for this class was generated from the following files:
Generated on Wed Feb 27 16:15:42 2008 for YAPET by  doxygen 1.5.4