-
Notifications
You must be signed in to change notification settings - Fork 2
/
databaseclient.hpp
72 lines (60 loc) · 2.38 KB
/
databaseclient.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef DATABASECLIENT_H
#define DATABASECLIENT_H
#include <QObject>
#include "database.hpp"
#include "crypto.hpp"
#include "paillierprivatekey.hpp"
class DatabaseClient : public QObject
{
Q_OBJECT
private:
const QCA::SecureArray kPrime;
const PaillierPrivateKey kPrimePrime;
const QCA::InitializationVector preEncryptIV;
const QCA::SecureArray ks;
const QCA::SecureArray kk;
QCA::SecureArray generateTi(DB::Word word, DB::Index index);
public:
explicit DatabaseClient(QObject *parent = 0);
/**
* @brief Encrypts the plaintext newRows to be stored in the database
* @param newRows The plaintext rows to be encrypted
* @param nextAvailableIndex The next available index on the server
*
* This method takes rows of plaintext data that need to be stored on the server, and encrypts them
* based on their index in the server, starting with nextAvailableIndex.
*
* @return The encrypted rows, which can be appended to the database
*/
DB::RowList encryptNewRows(DB::RowList newRows, DB::Index nextAvailableIndex);
/**
* @brief Decrypt the encrypted crypticRows from the database server for reading
* @param crypticRows The encrypted and indexed rows from the database server, which are to be
* decrypted
*
* After making a query to the server, it will return an indexed list of encrypted rows. This method
* will decrypt those rows and return them as plaintext.
*
* @return A decrypted version of crypticRows
*/
DB::RowList decryptRows(DB::IndexedRowList crypticRows);
/**
* @brief Encrypts the word plainText for searching within the database server
* @param plainText The plaintext word which is to be searched for in the database
*
* In order for the database server to search for a word, that word must be encrypted. This method
* will take a plaintext word and encrypt it so that the database server can search for it.
*
* @return An encrypted version of plainText which the server can search the database for
*/
QPair<DB::Word, QCA::SecureArray> encryptWordForSearch(DB::Word plainText);
PaillierPublicKey getPublicKey() {
return kPrimePrime.derivePublicKey();
}
QCA::BigInteger decryptNumber(QCA::BigInteger number) {
return kPrimePrime.decrypt(number);
}
signals:
public slots:
};
#endif // DATABASECLIENT_H