-
Notifications
You must be signed in to change notification settings - Fork 5
QBlockCipher
BrutalWizard edited this page Sep 22, 2020
·
12 revisions
Example:
#include <QByteArray>
#include "QBlockCipher.h"
int main() {
QSimpleCrypto::QBlockCipher blockCipher;
QByteArray key3 = "AABBCCEEFFGGHHKKLLMMNNOOPPRRSSTT";
QByteArray iv3 = "AABBCCEEFFGGHHKKLLMMNNOOPPRRSSTT";
QByteArray salt = blockCipher.generateRandomBytes(8);
QByteArray encrypted = blockCipher.encryptAesBlockCipher("Hello World!", key, iv, "password", salt, 14, EVP_aes_256_cbc(), EVP_sha512());
QByteArray decrypted = blockCipher.decryptAesBlockCipher(encrypted, key, iv, "password", salt, 14, EVP_aes_256_cbc(), EVP_sha512());
}
QByteArray generateRandomBytes(const int& size)
- size - Size of generated bytes
Returns random bytes. (Can be used for salt)
QByteArray encryptAesBlockCipher(QByteArray data, QByteArray key, QByteArray iv = "", QByteArray password = "", QByteArray salt = "", const int& rounds = 14, const EVP_CIPHER* cipher = EVP_aes_256_cbc(), const EVP_MD* md = EVP_sha512())
- data - Data that will be encrypted
- key - AES key
- iv - Initialization vector
- password - Encryption password
- salt - Random delta
- rounds - Transformation rounds
- cipher - Can be used with OpenSSL EVP_CIPHER (ecb, cbc, cfb, ofb, ctr) - 128, 192, 256. Example: EVP_aes_256_cbc()
- md - Hash algroitm (OpenSSL EVP_MD). Example: EVP_sha512()
Returns encrypted data or "", if error happened.
QByteArray decryptAesBlockCipher(QByteArray data, QByteArray key, QByteArray iv = "", QByteArray password = "", QByteArray salt = "", const int& rounds = 14, const EVP_CIPHER* cipher = EVP_aes_256_cbc(), const EVP_MD* md = EVP_sha512())
- data - Data that will be decrypted
- key - AES key
- iv - Initialization vector
- password - Decryption password
- salt - Random delta
- rounds - Transformation rounds
- cipher - Can be used with OpenSSL EVP_CIPHER (ecb, cbc, cfb, ofb, ctr) - 128, 192, 256. Example: EVP_aes_256_cbc()
- md - Hash algroitm (OpenSSL EVP_MD). Example: EVP_sha512()
Returns decrypted data or "", if error happened.