-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencryption.h
More file actions
107 lines (88 loc) · 2.36 KB
/
encryption.h
File metadata and controls
107 lines (88 loc) · 2.36 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef ENCRYPTION_H
#define ENCRYPTION_H
//
// Encryption Class
//
// DESCRIPTION
//
// The Encryption Class is capable of saving and loading encrypted files. All files are encrypted
// with the same key, which cannot be changed once set.
//
// The key itself is protected with a password, which must be entered each time the application is used.
// Note that multiple instances of he same application have access to the same key, so only the first
// application need login.
//
// THe login password can be changed if desired, and the key is re-encrypted with the new password.
// If the login password is forgotten, the {same} key can be re-installed, and a new login password
// can be created. It is essential that the key is not lost.
//
//
// EXAMPLE
//
// Encryption *enc = new Encryption("company", "application") ;
//
// if (!hasKey()) { setKey() ; }
// if (!loggedIn()) { login() ; }
//
// QString contents ;
//
// if (!load("file.enc", contents)) {
// // Error, couldn't load
// }
//
// if (!save("file.enc", contents)) {
// // Error, couldn't save
// }
//
#include <QDialog>
#include <QSharedMemory>
namespace Ui {
class Encryption;
}
class Encryption : public QDialog
{
Q_OBJECT
public:
typedef enum {
NoKey,
KeyLoaded,
KeyDecrypted,
KeyValidated
} State ;
typedef enum {
Write=0,
Read,
Delete,
Exists
} PasswordAction ;
private:
bool passwordStore(Encryption::PasswordAction action, QString& password) ;
bool saveKey() ;
public:
explicit Encryption(QString domain, QString application, QWidget *parent = 0);
~Encryption();
private:
// Unused copy construct
Encryption(const Encryption& other) ;
Encryption& operator= (const Encryption &rhs) ;
public:
// Dialog form functions
void setKey() ;
void changePassword() ;
void login() ;
void logout() ;
// Current Status
bool hasKey() ;
bool loggedIn() ;
// Load and Save File Data
bool load(QString filename, QByteArray &data) ;
bool save(QString filename, QByteArray data) ;
// Backup / restore key parameter "A", "B" or "C" (debug / diagnostic)
QString getKeyValue(QString type) ;
bool setKeyValue(QString type, QString string) ;
private:
QString sDomain, sApplication ;
Ui::Encryption *ui;
QSharedMemory sharedmem ;
};
#endif // ENCRYPTION_H