Update README.md

This commit is contained in:
Matteo Brichese 2018-04-05 16:16:11 -07:00 committed by GitHub
parent d96ee60dee
commit c0cf26380d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,10 +54,10 @@ Sample code using a 128bit key in ECB mode
``` ```
#include "qaesencryption.h" #include "qaesencryption.h"
QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB); QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB);
QByteArray encodedText = encryption.encode(plainText, key); QByteArray encodedText = encryption.encode(plainText, key);
QByteArray decodedText = encryption.decode(encodedText, key); QByteArray decodedText = encryption.decode(encodedText, key);
``` ```
Example for 256bit CBC using QString Example for 256bit CBC using QString
@ -65,23 +65,23 @@ Example for 256bit CBC using QString
#include <QCryptographicHash> #include <QCryptographicHash>
#include "qaesencryption.h" #include "qaesencryption.h"
QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::CBC); QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::CBC);
QString inputStr("The Advanced Encryption Standard (AES), also known by its original name Rijndael " 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. " "is a specification for the encryption of electronic data established by the U.S. "
"National Institute of Standards and Technology (NIST) in 2001"); "National Institute of Standards and Technology (NIST) in 2001");
QString key("your-string-key"); QString key("your-string-key");
QString iv("your-IV-vector"); QString iv("your-IV-vector");
QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256); QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256);
QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5); QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5);
QByteArray encodeText = encryption.encode(inputStr.toLocal8Bit(), hashKey, hashIV); QByteArray encodeText = encryption.encode(inputStr.toLocal8Bit(), hashKey, hashIV);
QByteArray decodeText = encryption.decode(encodeText, hashKey, hashIV); QByteArray decodeText = encryption.decode(encodeText, hashKey, hashIV);
QString decodedString = QString(encryption.removePadding(decodeText)); QString decodedString = QString(encryption.removePadding(decodeText));
//decodedString == inputStr !! //decodedString == inputStr !!
``` ```
### Example via static invocation ### Example via static invocation
@ -90,21 +90,21 @@ Static invocation without creating instances, 256 bit key, ECB mode, starting fr
#include <QCryptographicHash> #include <QCryptographicHash>
#include "qaesencryption.h" #include "qaesencryption.h"
QString inputStr("The Advanced Encryption Standard (AES), also known by its original name Rijndael " 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. " "is a specification for the encryption of electronic data established by the U.S. "
"National Institute of Standards and Technology (NIST) in 2001"); "National Institute of Standards and Technology (NIST) in 2001");
QString key("your-string-key"); QString key("your-string-key");
QString iv("your-IV-vector"); QString iv("your-IV-vector");
QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256); QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256);
QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5); QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5);
//Static invocation //Static invocation
QByteArray encrypted = QAESEncryption::Crypt(QAESEncryption::AES_256, QAESEncryption::CBC, QByteArray encrypted = QAESEncryption::Crypt(QAESEncryption::AES_256, QAESEncryption::CBC,
inputStr.toLocal8Bit(), hashKey, hashIV); inputStr.toLocal8Bit(), hashKey, hashIV);
//... //...
// Removal of Padding via Static function // Removal of Padding via Static function
QString decodedString = QString(QAESEncryption::RemovePadding(decodeText)); QString decodedString = QString(QAESEncryption::RemovePadding(decodeText));
``` ```