4
0
mirror of https://github.com/QuasarApp/Qt-AES.git synced 2025-05-01 15:59:36 +00:00

67 lines
2.5 KiB
Markdown
Raw Normal View History

2017-06-06 17:15:23 -07:00
# Qt-AES
2017-07-06 13:49:28 -07:00
Small and portable AES encryption class for Qt.
2017-07-07 10:08:29 -07:00
Supports all key sizes - 128/192/256 bits - ECB and CBC modes
2017-06-23 14:43:59 -07:00
## Usage
2017-07-03 11:08:18 -07:00
2017-07-06 14:30:08 -07:00
### Usage via instance
Example for 128bit ECB
```
#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
```
#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::Sha256);
2017-07-03 11:08:18 -07:00
2017-07-06 14:30:08 -07:00
QByteArray encodeText = encryption.encode(inputStr.toLocal8Bit(), hashKey, hashIV);
QByteArray decodeText = encryption.decode(encodeText, hashKey, hashIV);
2017-07-03 11:08:18 -07:00
```
2017-07-06 14:30:08 -07:00
### Usage via static invocation
Example of static invocation without creating instances
```
#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::Sha256);
//Static invocation
QAESEncryption::Crypt(QAESEncryption::AES_256, QAESEncryption::CBC, inputStr.toLocal8Bit(), hashKey, hashIV);
```
2017-07-07 10:08:29 -07:00
## Unit Testing
2017-07-07 13:24:57 -07:00
The unit testing vectors used are included in [NIST-Recommendation for Block Cipher Modes of Operation](http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf)
2017-07-07 10:08:29 -07:00
2017-07-06 14:30:08 -07:00
## Contact
Question or suggestions are welcome!
Please use the GitHub issue tracking to report suggestions or issues.
## Licence
This software is provided under the [UNLICENSE](http://unlicense.org/)