#include <QtCrypto>
Public Types | |
enum | Mode { CBC, CFB, ECB, OFB } |
enum | Padding { DefaultPadding, NoPadding, PKCS7 } |
Public Member Functions | |
int | blockSize () const |
Cipher (const Cipher &from) | |
Cipher (const QString &type, Mode mode, Padding pad=DefaultPadding, Direction dir=Encode, const SymmetricKey &key=SymmetricKey(), const InitializationVector &iv=InitializationVector(), const QString &provider=QString()) | |
virtual void | clear () |
Direction | direction () const |
virtual MemoryRegion | final () |
KeyLength | keyLength () const |
Mode | mode () const |
virtual bool | ok () const |
Cipher & | operator= (const Cipher &from) |
Padding | padding () const |
void | setup (Direction dir, const SymmetricKey &key, const InitializationVector &iv=InitializationVector()) |
QString | type () const |
virtual MemoryRegion | update (const MemoryRegion &a) |
bool | validKeyLength (int n) const |
Static Public Member Functions | |
static QStringList | supportedTypes (const QString &provider=QString()) |
static QString | withAlgorithms (const QString &cipherType, Mode modeType, Padding paddingType) |
Cipher is the class for the various algorithms that perform low level encryption and decryption within QCA.
AES128, AES192 and AES256 are recommended for new applications.
Standard names for ciphers are:
When checking for the availability of a particular kind of cipher operation (e.g. AES128 in CBC mode with PKCS7 padding), you append the mode and padding type (in that example "aes128-cbc-pkcs7"). CFB and OFB modes don't use padding, so they are always just the cipher name followed by the mode (e.g. "blowfish-cfb" or "aes192-ofb"). If you are not using padding with CBC mode (i.e. you are ensuring block size operations yourself), just use the cipher name followed by "-cbc" (e.g. "blowfish-cbc" or "aes256-cbc").
aes-cmac.cpp, and ciphertest.cpp.
enum QCA::Cipher::Mode |
Mode settings for cipher algorithms.
enum QCA::Cipher::Padding |
Padding variations for cipher algorithms.
See the Padding description for more details on padding schemes.
QCA::Cipher::Cipher | ( | const QString & | type, | |
Mode | mode, | |||
Padding | pad = DefaultPadding , |
|||
Direction | dir = Encode , |
|||
const SymmetricKey & | key = SymmetricKey() , |
|||
const InitializationVector & | iv = InitializationVector() , |
|||
const QString & | provider = QString() | |||
) |
Standard constructor.
type | the name of the cipher specialisation to use (e.g. "aes128") | |
mode | the operating Mode to use (e.g. QCA::Cipher::CBC) | |
pad | the type of Padding to use | |
dir | the Direction that this Cipher should use (Encode for encryption, Decode for decryption) | |
key | the SymmetricKey array that is the key | |
iv | the InitializationVector to use (not used for ECB mode) | |
provider | the name of the Provider to use |
QCA::Cipher::Cipher | ( | const Cipher & | from | ) |
int QCA::Cipher::blockSize | ( | ) | const |
return the block size for the cipher object
virtual void QCA::Cipher::clear | ( | ) | [virtual] |
Direction QCA::Cipher::direction | ( | ) | const |
Return the cipher direction.
virtual MemoryRegion QCA::Cipher::final | ( | ) | [virtual] |
complete the block of data, padding as required, and returning the completed block
Implements QCA::Filter.
KeyLength QCA::Cipher::keyLength | ( | ) | const |
Return acceptable key lengths.
Mode QCA::Cipher::mode | ( | ) | const |
Return the cipher mode.
virtual bool QCA::Cipher::ok | ( | ) | const [virtual] |
Test if an update() or final() call succeeded.
Implements QCA::Filter.
Padding QCA::Cipher::padding | ( | ) | const |
Return the cipher padding type.
void QCA::Cipher::setup | ( | Direction | dir, | |
const SymmetricKey & | key, | |||
const InitializationVector & | iv = InitializationVector() | |||
) |
Reset / reconfigure the Cipher.
You can use this to re-use an existing Cipher, rather than creating a new object with a slightly different configuration.
dir | the Direction that this Cipher should use (Encode for encryption, Decode for decryption) | |
key | the SymmetricKey array that is the key | |
iv | the InitializationVector to use (not used for ECB Mode) |
static QStringList QCA::Cipher::supportedTypes | ( | const QString & | provider = QString() |
) | [static] |
Returns a list of all of the cipher types available.
provider | the name of the provider to get a list from, if one provider is required. If not specified, available cipher types from all providers will be returned. |
QString QCA::Cipher::type | ( | ) | const |
virtual MemoryRegion QCA::Cipher::update | ( | const MemoryRegion & | a | ) | [virtual] |
pass in a byte array of data, which will be encrypted or decrypted (according to the Direction that was set in the constructor or in setup() ) and returned.
a | the array of data to encrypt / decrypt |
Implements QCA::Filter.
bool QCA::Cipher::validKeyLength | ( | int | n | ) | const |
Test if a key length is valid for the cipher algorithm.
n | the key length in bytes |
static QString QCA::Cipher::withAlgorithms | ( | const QString & | cipherType, | |
Mode | modeType, | |||
Padding | paddingType | |||
) | [static] |
Construct a Cipher type string.
cipherType | the name of the algorithm (eg AES128, DES) | |
modeType | the mode to operate the cipher in (eg QCA::CBC, QCA::CFB) | |
paddingType | the padding required (eg QCA::NoPadding, QCA::PCKS7) |