|
LibLogicalAccess
2.5.0
An Open Source RFID Library
|
A OpenSSL symmetric cipher base class. More...
#include <openssl_symmetric_cipher.hpp>
Public Types | |
| enum | EncMode { ENC_MODE_CBC , ENC_MODE_CFB , ENC_MODE_CFB1 , ENC_MODE_CFB8 , ENC_MODE_ECB , ENC_MODE_OFB } |
| Encryption mode. More... | |
| enum | Method { M_ENCRYPT , M_DECRYPT } |
| A method. More... | |
Public Member Functions | |
| OpenSSLSymmetricCipher (EncMode mode) | |
| Constructor. | |
| virtual | ~OpenSSLSymmetricCipher () |
| OpenSSLSymmetricCipherContext | start (Method method, const SymmetricKey &key, const InitializationVector &iv, bool padding) const |
| Initialize a new encryption/decryption session. | |
| void | cipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key, const InitializationVector &iv, bool padding) override |
| Cipher a buffer. | |
| void | decipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key, const InitializationVector &iv, bool padding) override |
| Decipher a buffer. | |
Public Member Functions inherited from logicalaccess::openssl::SymmetricCipher | |
| virtual | ~SymmetricCipher () |
| Destructor. | |
| virtual void | cipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key, const InitializationVector &iv, bool padding)=0 |
| Cipher a buffer. | |
| void | cipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key) |
| void | cipher (const ByteVector &src, ByteVector &dest, const ByteVector &key, const ByteVector &iv={}) |
| virtual void | decipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key, const InitializationVector &iv, bool padding)=0 |
| Decipher a buffer. | |
| void | decipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key) |
| void | decipher (const ByteVector &src, ByteVector &dest, const ByteVector &key, const ByteVector &iv={}) |
| virtual unsigned char | getBlockSize () const =0 |
Static Public Member Functions | |
| static void | update (OpenSSLSymmetricCipherContext &context, const ByteVector &src) |
| Add data to encrypt/decrypt. | |
| static ByteVector | stop (OpenSSLSymmetricCipherContext &context) |
| Finalize an encryption/decryption session. | |
Protected Member Functions | |
| virtual const EVP_CIPHER * | getEVPCipher (const SymmetricKey &key) const =0 |
| Get the openssl EVP cipher. | |
| EncMode | mode () const |
| Get the encryption mode. | |
Private Attributes | |
| EncMode | d_mode |
| The encryption mode. | |
A OpenSSL symmetric cipher base class.
This class serves as a base for all OpenSSL based symmetric cipher classes.
To cipher or decipher a buffer, you can use the start() method to get a context, use update() to fill-in a data block and stop() to get the ciphered/deciphered resulting data.
OpenSSLSymmetricCipher also provides helper methods cipher() and decipher() to quickly cipher or decipher a buffer.
|
explicit |
Constructor.
| mode | The encryption mode. |
|
virtual |
|
overridevirtual |
Cipher a buffer.
| src | The buffer to cipher. |
| dest | The ciphered buffer. |
| key | The key to use. |
| iv | The initialisation vector. |
| padding | Whether to use padding. In case of a failure, the call an InvalidCallException. |
Implements logicalaccess::openssl::SymmetricCipher.
|
overridevirtual |
Decipher a buffer.
| src | The buffer to decipher. |
| dest | The deciphered buffer. |
| key | The key to use. |
| iv | The initialisation vector. |
| padding | Whether to use padding. In case of a failure, the call a InvalidCallException. |
Implements logicalaccess::openssl::SymmetricCipher.
|
protectedpure virtual |
Get the openssl EVP cipher.
| key | The key. |
Implemented in logicalaccess::openssl::AESCipher, and logicalaccess::openssl::DESCipher.
|
inlineprotected |
Get the encryption mode.
| OpenSSLSymmetricCipherContext logicalaccess::openssl::OpenSSLSymmetricCipher::start | ( | Method | method, |
| const SymmetricKey & | key, | ||
| const InitializationVector & | iv, | ||
| bool | padding | ||
| ) | const |
Initialize a new encryption/decryption session.
| method | The method. |
| key | The key to use. |
| iv | The initialisation vector. |
| padding | Whether to use padding. |
|
static |
|
static |
Add data to encrypt/decrypt.
| context | The context. |
| src | The data to add to the encrypt/decrypt session. |
|
private |
The encryption mode.
1.9.6