![]() |
QtLingo 1
QtLingo is an Application to make Qt Computer Translations easier
|
Simple encryption and decryption of strings and byte arrays. More...
#include <SimpleCrypt.h>
Public Types | |
enum | CompressionMode { CompressionAuto , CompressionAlways , CompressionNever } |
enum | IntegrityProtectionMode { ProtectionNone , ProtectionChecksum , ProtectionHash } |
enum | Error { ErrorNoError , ErrorNoKeySet , ErrorUnknownVersion , ErrorIntegrityFailed } |
enum | CryptoFlag { CryptoFlagNone = 0 , CryptoFlagCompression = 0x01 , CryptoFlagChecksum = 0x02 , CryptoFlagHash = 0x04 } |
Public Member Functions | |
SimpleCrypt () | |
Constructor. SimpleCrypt. More... | |
SimpleCrypt (quint64 key) | |
Constructor. SimpleCrypt. More... | |
void | setKey (quint64 key) |
set Key. setKey More... | |
bool | hasKey () const |
void | setCompressionMode (CompressionMode mode) |
CompressionMode | compressionMode () const |
void | setIntegrityProtectionMode (IntegrityProtectionMode mode) |
IntegrityProtectionMode | integrityProtectionMode () const |
Error | lastError () const |
QString | encryptToString (const QString &plaintext) |
encrypt To String QString. encryptToString More... | |
QString | encryptToString (const QByteArray &plaintext) |
encrypt To String QByteArray. encryptToString More... | |
QByteArray | encryptToByteArray (const QString &plaintext) |
encrypt To Byte Array QString. encryptToByteArray More... | |
QByteArray | encryptToByteArray (const QByteArray &plaintext) |
encrypt To Byte Array QByteArray. encryptToByteArray More... | |
QString | decryptToString (const QString &cyphertext) |
decrypt To String QString. decryptToString More... | |
QByteArray | decryptToByteArray (const QString &cyphertext) |
decrypt To Byte Array QString. decryptToByteArray More... | |
QString | decryptToString (const QByteArray &cypher) |
decrypt To String QByteArray. decryptToString More... | |
QByteArray | decryptToByteArray (QByteArray cypher) |
decrypt To Byte Array QByteArray. decryptToByteArray More... | |
Q_DECLARE_FLAGS (CryptoFlags, CryptoFlag) | |
void | setDebugMessage (bool thisState) |
set Debug Message More... | |
bool | getDebugMessage () |
get Debug Message More... | |
void | setMessage (const QString &thisMessage) |
set Message More... | |
Simple encryption and decryption of strings and byte arrays.
This class provides a simple implementation of encryption and decryption of strings and byte arrays.
The class uses a 64 bit key. Simply create an instance of the class, set the key, and use the encryptToString() method to calculate an encrypted version of the input string. To decrypt that string again, use an instance of SimpleCrypt initialized with the same key, and call the decryptToString() method with the encrypted string. If the key matches, the decrypted version of the string will be returned again.
If you do not provide a key, or if something else is wrong, the encryption and decryption function will return an empty string or will return a string containing nonsense. lastError() will return a value indicating if the method was succesful, and if not, why not.
SimpleCrypt is prepared for the case that the encryption and decryption algorithm is changed in a later version, by prepending a version identifier to the cypertext.
Definition at line 71 of file SimpleCrypt.h.
CompressionMode describes if compression will be applied to the data to be encrypted.
Definition at line 77 of file SimpleCrypt.h.
enum to describe options that have been used for the encryption. Currently only one, but that only leaves room for future extensions like adding a cryptographic hash...
Definition at line 204 of file SimpleCrypt.h.
enum SimpleCrypt::Error |
Definition at line 96 of file SimpleCrypt.h.
IntegrityProtectionMode describes measures taken to make it possible to detect problems with the data, or wrong decryption keys. Measures involve adding a checksum or a cryptograhpic hash to the data to be encrypted. This increases the length of the resulting cypertext, but makes it possible to check if the plaintext appears to be valid after decryption.
Definition at line 89 of file SimpleCrypt.h.
SimpleCrypt::SimpleCrypt | ( | ) |
Constructor. SimpleCrypt.
Constructor. Constructs a SimpleCrypt instance without a valid key set on it.
Definition at line 34 of file SimpleCrypt.cpp.
|
explicit |
Constructor. SimpleCrypt.
Constructor. Constructs a SimpleCrypt instance and initializes it with the given
Definition at line 44 of file SimpleCrypt.cpp.
|
inline |
Returns the CompressionMode that is currently in use.
Definition at line 130 of file SimpleCrypt.h.
QByteArray SimpleCrypt::decryptToByteArray | ( | const QString & | cyphertext | ) |
decrypt To Byte Array QString. decryptToByteArray
Decrypts a cyphertext string encrypted with this class with the set key back to the plain text version.
If an error occured, such as non-matching keys between encryption and decryption, an empty string or a string containing nonsense may be returned.
Definition at line 222 of file SimpleCrypt.cpp.
QByteArray SimpleCrypt::decryptToByteArray | ( | QByteArray | cypher | ) |
decrypt To Byte Array QByteArray. decryptToByteArray
Decrypts a cyphertext binary encrypted with this class with the set key back to the plain text version.
If an error occured, such as non-matching keys between encryption and decryption, an empty string or a string containing nonsense may be returned.
Definition at line 233 of file SimpleCrypt.cpp.
QString SimpleCrypt::decryptToString | ( | const QByteArray & | cypher | ) |
decrypt To String QByteArray. decryptToString
Decrypts a cyphertext binary encrypted with this class with the set key back to the plain text version. If an error occured, such as non-matching keys between encryption and decryption, an empty string or a string containing nonsense may be returned.
Definition at line 211 of file SimpleCrypt.cpp.
QString SimpleCrypt::decryptToString | ( | const QString & | cyphertext | ) |
decrypt To String QString. decryptToString
Decrypts a cyphertext string encrypted with this class with the set key back to the plain text version.
If an error occured, such as non-matching keys between encryption and decryption, an empty string or a string containing nonsense may be returned.
Definition at line 199 of file SimpleCrypt.cpp.
QByteArray SimpleCrypt::encryptToByteArray | ( | const QByteArray & | plaintext | ) |
encrypt To Byte Array QByteArray. encryptToByteArray
Encrypts the
This method returns a byte array, that is useable for storing a binary format. If you need a string you can store in a text file, use encryptToString() instead.
Definition at line 105 of file SimpleCrypt.cpp.
QByteArray SimpleCrypt::encryptToByteArray | ( | const QString & | plaintext | ) |
encrypt To Byte Array QString. encryptToByteArray
Encrypts the
This method returns a byte array, that is useable for storing a binary format. If you need a string you can store in a text file, use encryptToString() instead.
Definition at line 96 of file SimpleCrypt.cpp.
QString SimpleCrypt::encryptToString | ( | const QByteArray & | plaintext | ) |
encrypt To String QByteArray. encryptToString
Encrypts the
Definition at line 189 of file SimpleCrypt.cpp.
QString SimpleCrypt::encryptToString | ( | const QString & | plaintext | ) |
encrypt To String QString. encryptToString
Encrypts the
Definition at line 178 of file SimpleCrypt.cpp.
bool SimpleCrypt::getDebugMessage | ( | ) |
|
inline |
Returns true if SimpleCrypt has been initialized with a key.
Definition at line 120 of file SimpleCrypt.h.
|
inline |
Definition at line 138 of file SimpleCrypt.h.
|
inline |
Definition at line 141 of file SimpleCrypt.h.
SimpleCrypt::Q_DECLARE_FLAGS | ( | CryptoFlags | , |
CryptoFlag | |||
) |
|
inline |
Sets the compression mode to use when encrypting data. The default mode is Auto.
Note that decryption is not influenced by this mode, as the decryption recognizes what mode was used when encrypting.
Definition at line 126 of file SimpleCrypt.h.
void SimpleCrypt::setDebugMessage | ( | bool | thisState | ) |
|
inline |
Sets the integrity mode to use when encrypting data. The default mode is Checksum.
Note that decryption is not influenced by this mode, as the decryption recognizes what mode was used when encrypting.
Definition at line 136 of file SimpleCrypt.h.
void SimpleCrypt::setKey | ( | quint64 | key | ) |
set Key. setKey
(Re-) initializes the key with the given
Definition at line 71 of file SimpleCrypt.cpp.
void SimpleCrypt::setMessage | ( | const QString & | thisMessage | ) |