2019-07-20 19:32:39 +03:00
# 
2019-06-22 13:59:33 +03:00
2019-07-19 10:31:46 +03:00
Fast encryption library supporting RSA and AES algorithms.
2019-06-05 13:48:23 +03:00
# Futures
The Qt-Secret library supports the following algorithms:
2019-06-06 15:21:59 +03:00
### RSA
2019-07-19 10:31:46 +03:00
The current implementation supports the following key sizes:
2019-06-05 13:48:23 +03:00
#### Supported sizes
2019-07-19 10:31:46 +03:00
* RSA64
* RSA128
* RSA256
* RSA512
* RSA1024
* RSA2048
* RSA4096
* RSA8192
2019-06-05 13:48:23 +03:00
#### Supported futures
* Encryption and decryption of messages.
* Signature and verification of the message signature.
2019-06-06 15:21:59 +03:00
### AES
2019-06-05 13:51:32 +03:00
Aes implementation was borrowed from [bricke ](https://github.com/bricke/Qt-AES ), because it fulfills the goals of this library.
2019-06-05 13:51:53 +03:00
Individual thanks [bricke ](https://github.com/bricke ) for implementing the AES encryption class.
2019-06-05 13:48:23 +03:00
#### AES Levels
The class supports all AES key lenghts
* AES_128
* AES_192
* AES_256
#### Modes
The class supports the following operating modes
* ECB
* CBC
* CFB
* OFB
#### Padding
By default the padding method is `ISO` , however, the class supports:
* ZERO
* PKCS7
* ISO
# Build
* git clone https://github.com/QuasarApp/Qt-Secret.git
* cd Qt-Secret
* git submodule update --init --recursive
2019-10-07 12:15:37 +03:00
* sudo apt install qt5-default
2019-10-07 12:29:18 +03:00
* qmake -r DEFINE+=WITHOUT_GUI Qt-Secret.pro
2019-10-07 13:08:43 +03:00
> DEFINE+=WITHOUT_GUI fot build without gui example, if you want build gui example remove this line. For build the gui example you need to install qml controls 2 in you os. Try **sudo apt install qml-module-qtquick-controls2 qtdeclarative5-dev qtdeclarative5-qtquick2-plugin**
2019-06-05 13:48:23 +03:00
* make -j8
* make test #(for testing)
# Include
## for qmake projects
* cd yourRepo
* git submodule add https://github.com/QuasarApp/Qt-Secret.git # add the repository of Qt-Secret into your repo like submodule
* git submodule update --init --update
2019-09-20 16:49:17 +03:00
* Add to the list of libraries for the Qt-Secret assembly. For an example you can create Main.Pro in which connect Qt-Secret and your project pro files as subprojects.
**Main.pro:**
``` qmake
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += \
Qt-Secret \
MyProject
```
* Include in your MyProject.pro file the pri file of Qt-Secret library
>> include($$PWD/../Qt-Secret/src/Qt-Secret.pri)
2019-06-05 13:48:23 +03:00
* Rebuild yuor project
## for other build system
* cd yourRepo
* git submodule add https://github.com/QuasarApp/Qt-Secret.git # add the repository of Qt-Secret into your repo like submodule
* git submodule update --init --update
* Add the rule for build Qt-Secret
* Add INCLUDEPATH and LIBS for your build system
* Rebuild yuor project
# Usage
## RSA
2019-06-05 14:53:01 +03:00
### Encryption and decryption of messages.
2019-06-05 13:48:23 +03:00
``` cpp
#include <qrsaencryption.h>
QByteArray pub, priv;
2019-07-20 19:41:36 +03:00
QRSAEncryption e(QRSAEncryption::Rsa::RSA_2048);
2019-11-16 10:28:48 +03:00
e.generatePairKey(pub, priv); // or other rsa size
2019-06-05 13:48:23 +03:00
QByteArray msg = "test message";
2019-11-16 10:28:48 +03:00
auto signedMessage = e.signMessage(msg, priv);
if (e.checkSignMessage(signedMessage, pub)) {
qInfo() < < " message signed success";
}
2019-06-05 13:48:23 +03:00
```
### Signature and verification of the message signature.
``` cpp
#include <qrsaencryption.h>
2019-11-16 10:28:48 +03:00
bool testExample() {
2019-06-05 13:48:23 +03:00
QByteArray pub, priv;
2019-11-16 10:28:48 +03:00
QRSAEncryption e(QRSAEncryption::Rsa::RSA_2048);
e.generatePairKey(pub, priv); // or other rsa size
2019-06-05 13:48:23 +03:00
QByteArray msg = "test message";
auto signedMessage = e.signMessage(msg, priv);
if (e.checkSignMessage(signedMessage, pub)) {
2019-11-16 10:28:48 +03:00
qInfo() < < " message signed success";
return true;
2019-06-05 13:48:23 +03:00
}
2019-11-16 10:28:48 +03:00
return false;
}
2019-06-05 13:48:23 +03:00
```
## AES
Sample code using a 128bit key in ECB mode
``` cpp
#include "qaesencryption.h"
QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB);
QByteArray encodedText = encryption.encode(plainText, key);
QByteArray decodedText = encryption.decode(encodedText, key);
```
Example for 256bit CBC using QString
``` cpp
#include <QCryptographicHash>
#include "qaesencryption.h"
QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::CBC);
QString inputStr("The Advanced Encryption Standard (AES), also known by its original name Rijndael "
"is a specification for the encryption of electronic data established by the U.S. "
"National Institute of Standards and Technology (NIST) in 2001");
QString key("your-string-key");
QString iv("your-IV-vector");
QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256);
QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5);
QByteArray encodeText = encryption.encode(inputStr.toLocal8Bit(), hashKey, hashIV);
QByteArray decodeText = encryption.decode(encodeText, hashKey, hashIV);
QString decodedString = QString(encryption.removePadding(decodeText));
2019-06-22 13:59:33 +03:00
//decodedString == inputStr !!!
2019-06-05 13:48:23 +03:00
```
### Example via static invocation
Static invocation without creating instances, 256 bit key, ECB mode, starting from *QString* text/key
2019-06-05 13:49:55 +03:00
``` cpp
2019-06-05 13:48:23 +03:00
#include <QCryptographicHash>
#include "qaesencryption.h"
QString inputStr("The Advanced Encryption Standard (AES), also known by its original name Rijndael "
"is a specification for the encryption of electronic data established by the U.S. "
"National Institute of Standards and Technology (NIST) in 2001");
QString key("your-string-key");
QString iv("your-IV-vector");
QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256);
QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5);
//Static invocation
QByteArray encrypted = QAESEncryption::Crypt(QAESEncryption::AES_256, QAESEncryption::CBC,
inputStr.toLocal8Bit(), hashKey, hashIV);
//...
// Removal of Padding via Static function
QString decodedString = QString(QAESEncryption::RemovePadding(decodeText));
```