Skip to content

QBlockCipher

BrutalWizard edited this page Dec 24, 2023 · 12 revisions

Example:

#include <QByteArray>

#include "QBlockCipher.h"

int main() {
    QSimpleCrypto::QBlockCipher blockCipher;

    QByteArray key = "AABBCCEEFFGGHHKKLLMMNNOOPPRRSSTT";
    QByteArray iv = "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());
}

Detailed Description

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. Example: "AABBCCEEFFGGHHKKLLMMNNOOPPRRSSTT"
  • iv - Initialization vector. Example: "AABBCCEEFFGGHHKKLLMMNNOOPPRRSSTT"
  • password - Encryption password
  • salt - Random delta. Example: "qwerty123" or another random bytes generated with QSimpleCrypto::QBlockCipher::generateSalt.
  • 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 on success and "" on failure.

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. Example: "AABBCCEEFFGGHHKKLLMMNNOOPPRRSSTT"
  • iv - Initialization vector. Example: "AABBCCEEFFGGHHKKLLMMNNOOPPRRSSTT"
  • password - Decryption password
  • salt - Random delta. Example: "qwerty123" or another random bytes generated with QSimpleCrypto::QBlockCipher::generateSalt.
  • 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 on success and "" on failure.

Clone this wiki locally