File indexing completed on 2024-05-12 04:58:26
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2013-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com> 0004 * Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com> 0005 * 0006 * This is based on a work by Saju Pillai <saju.pillai@gmail.com> 0007 * 0008 * This program is free software: you can redistribute it and/or modify 0009 * it under the terms of the GNU General Public License as published by 0010 * the Free Software Foundation, either version 3 of the License, or 0011 * (at your option) any later version. 0012 * 0013 * This program is distributed in the hope that it will be useful, 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0016 * GNU General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU General Public License 0019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0020 * ============================================================ */ 0021 #ifndef AESINTERFACE_H 0022 #define AESINTERFACE_H 0023 0024 #include "qzcommon.h" 0025 0026 #include <openssl/evp.h> 0027 0028 #include <QObject> 0029 #include <QHash> 0030 #include <QList> 0031 0032 class FALKON_EXPORT AesInterface : public QObject 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 static const int VERSION; 0038 0039 explicit AesInterface(QObject* parent = nullptr); 0040 ~AesInterface(); 0041 0042 bool isOk() const; 0043 0044 QByteArray encrypt(const QByteArray &plainData, const QByteArray &password); 0045 QByteArray decrypt(const QByteArray &cipherData, const QByteArray &password); 0046 0047 static QByteArray passwordToHash(const QString &masterPassword); 0048 static QByteArray createRandomData(int length); 0049 0050 private: 0051 bool init(int evpMode, const QByteArray &password, const QByteArray &iVector = QByteArray()); 0052 0053 EVP_CIPHER_CTX* m_encodeCTX; 0054 EVP_CIPHER_CTX* m_decodeCTX; 0055 0056 bool m_ok = false; 0057 QByteArray m_iVector; 0058 }; 0059 #endif //AESINTERFACE_H