示例#1
0
/**
 * @paragraph This method encrypts a data string and returns a map of the key, hash and vector
 * @brief ServerPanel::EncryptEntity
 * @param QString sData
 * @return QVariantMap
 */
QVariantMap ServerPanel::EncryptEntity(QString sData) {
    // Initialize the cryptographer
    QCA::Initializer qiInitialization           = QCA::Initializer();
    // Generate the key
    QCA::SymmetricKey qskKey                    = QCA::SymmetricKey(2048);
    // Generate the vector
    QCA::InitializationVector qivInitialization = QCA::InitializationVector(2048);
    // Create the cipher
    QCA::Cipher qcrCipher                       = QCA::Cipher("aes128", QCA::Cipher::CBC, QCA::Cipher::DefaultPadding, QCA::Encode, qskKey, qivInitialization);
    // Make sure AES128 is supported
    if (!QCA::isSupported("aes128-cbc-pkcs7")) {
        qDebug("AES128 CBC PKCS7 not supported - please check if qca-ossl plugin installed correctly !");
    }
    // Encrypt the data
    QCA::SecureArray qsaHash = qcrCipher.process(QCA::SecureArray(sData.toAscii()));
    // Setup the map to resturn
    QVariantMap qvmReturn;
    // Add the key
    qvmReturn.insert("qbaKey",    qskKey.toByteArray());
    // Add the vector
    qvmReturn.insert("qbaVector", qivInitialization.toByteArray());
    // Add the hash
    qvmReturn.insert("qbaHash",   qsaHash.toByteArray());
    // Return the map
    return qvmReturn;
}
示例#2
0
QByteArray Utils::encrypt(const QByteArray & msg, const QString & password)
{
    QCA::Cipher cipher(QString("aes128"), QCA::Cipher::CBC, QCA::Cipher::DefaultPadding);

    QCA::SymmetricKey key = QCA::SymmetricKey(password.toAscii());
    QCA::InitializationVector iv = QCA::InitializationVector(16);

    cipher.setup(QCA::Encode, key, iv);

    QByteArray ret = iv.toByteArray();
    ret += cipher.process(msg).toByteArray();
    return ret;
}
void QgsAuthCrypto::passwordKeyHash( const QString& pass, QString *salt, QString *hash, QString *cipheriv )
{
  if ( QgsAuthCrypto::isDisabled() )
    return;

  QCA::InitializationVector saltiv = QCA::InitializationVector( KEY_GEN_IV_LENGTH );
  QCA::SymmetricKey key = passwordKey_( pass, saltiv );

  if ( !key.isEmpty() )
  {
    *salt = QCA::arrayToHex( saltiv.toByteArray() );
    qDebug( "salt hex: %s", qPrintable( *salt ) );

    *hash = QCA::arrayToHex( key.toByteArray() );
    qDebug( "hash hex: %s", qPrintable( *hash ) );

    if ( cipheriv )
    {
      *cipheriv = QCA::arrayToHex( QCA::InitializationVector( CIPHER_IV_LENGTH ).toByteArray() );
      qDebug( "cipheriv hex: %s", qPrintable( *cipheriv ) );
    }
  }
}