-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcipher.h
63 lines (44 loc) · 1.28 KB
/
cipher.h
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
#ifndef CIPHER_H
#define CIPHER_H
#include <QObject>
#include <QDebug>
#include <QFile>
#include <openssl/rsa.h>
#include <openssl/engine.h>
#include <openssl/pem.h>
#include <openssl/conf.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/decoder.h>
#include <openssl/aes.h>
#define PADDING RSA_PKCS1_PADDING
#define KEYSIZE 32
#define IVSIZE 32
#define BLOCKSIZE 256
#define SALTSIZE 8
class Cipher : public QObject
{
Q_OBJECT
public:
explicit Cipher(QObject *parent = nullptr);
~Cipher();
EVP_PKEY *getPublicKey(QByteArray &data);
EVP_PKEY *getPublicKey(QString filename);
EVP_PKEY *getPrivateKey(QByteArray &data);
EVP_PKEY *getPrivateKey(QString filename);
QByteArray encryptRSA(EVP_PKEY *key, QByteArray &data);
QByteArray decryptRSA(EVP_PKEY *key, QByteArray &data);
QByteArray encryptAES(QByteArray passphrase, QByteArray &data);
QByteArray decryptAES(QByteArray passphrase, QByteArray &data);
QByteArray randomBytes(int size);
EVP_PKEY *createRSAKeyPair(int key_size);
void freeEVPKey(EVP_PKEY *key);
QByteArray readFile(QString filename);
void writeFile(QString filename, QByteArray &data);
signals:
private:
void initialize();
void finalize();
};
#endif // CIPHER_H