24 #define CIPHER_SIGNATURE "aes256-cbc-pkcs7"
25 #define CIPHER_TYPE "aes256"
26 #define CIPHER_MODE QCA::Cipher::CBC
27 #define CIPHER_PADDING QCA::Cipher::PKCS7
28 #define CIPHER_IV_LENGTH 32
29 #define CIPHER_PROVIDER "qca-ossl"
30 #define PASSWORD_HASH_ALGORITHM "sha256"
31 #define RANDOM_KEY_LENGTH 16
32 #define KEY_GEN_ITERATIONS 10000
33 #define KEY_GEN_LENGTH 16
34 #define KEY_GEN_IV_LENGTH 16
40 qDebug(
"Authentication system DISABLED: QCA's qca-ossl (OpenSSL) plugin is missing" );
51 return encryptdecrypt( pass, cipheriv, text,
true );
59 return encryptdecrypt( pass, cipheriv, text,
false );
74 QCA::InitializationVector saltiv = QCA::InitializationVector(
KEY_GEN_IV_LENGTH );
79 *salt = QCA::arrayToHex( saltiv.toByteArray() );
80 qDebug(
"salt hex: %s", qPrintable( *salt ) );
82 *hash = QCA::arrayToHex( key.toByteArray() );
83 qDebug(
"hash hex: %s", qPrintable( *hash ) );
87 *cipheriv = QCA::arrayToHex( QCA::InitializationVector(
CIPHER_IV_LENGTH ).toByteArray() );
88 qDebug(
"cipheriv hex: %s", qPrintable( *cipheriv ) );
101 QCA::InitializationVector saltiv( QCA::hexToArray( salt ) );
106 *hashderived = derived;
109 return hash == derived;
121 QCA::InitializationVector iv( QCA::hexToArray( cipheriv ) );
128 QCA::Encode, key, iv,
131 QCA::SecureArray securedata( textstr.
toUtf8() );
132 QCA::SecureArray encrypteddata( cipher.process( securedata ) );
135 qDebug(
"Encryption failed!" );
138 outtxt = QCA::arrayToHex( encrypteddata.toByteArray() );
144 QCA::Decode, key, iv,
147 QCA::SecureArray ciphertext( QCA::hexToArray( textstr ) );
148 QCA::SecureArray decrypteddata( cipher.process( ciphertext ) );
151 qDebug(
"Decryption failed!" );
155 outtxt =
QString( decrypteddata.toByteArray() );
static bool verifyPasswordKeyHash(const QString &pass, const QString &salt, const QString &hash, QString *hashderived=0)
Verify existing master password hash to a re-generated one.
const char * constData() const
#define KEY_GEN_ITERATIONS
#define KEY_GEN_IV_LENGTH
#define PASSWORD_HASH_ALGORITHM
static void passwordKeyHash(const QString &pass, QString *salt, QString *hash, QString *cipheriv=0)
Generate SHA256 hash for master password, with iterations and salt.
static const QString encrypt(const QString &pass, const QString &cipheriv, const QString &text)
Encrypt data using master password.
static QCA::SymmetricKey passwordKey_(const QString &pass, const QCA::InitializationVector &salt)
static const QString decrypt(const QString &pass, const QString &cipheriv, const QString &text)
Decrypt data using master password.
static bool isDisabled()
Whether QCA has the qca-ossl plugin, which a base run-time requirement.
QByteArray toUtf8() const