· 8 years ago · May 10, 2018, 06:58 PM
1Building cryptopp:
2Mac OS:
31. Download sources from https://www.cryptopp.com/. You should use the latest version.
4Now it is: https://github.com/weidai11/cryptopp/releases/tag/CRYPTOPP_7_0_0
52. Extract archive to any place
63. Compile library: "make libcryptopp.a" for static library Or "make libcryptopp.so" for dynamic library.
74. Install libraries and headers "make install PREFIX=$PWD/installed"
85. Copy library and headers from install folder to deps folder
9
10Windows:
11MinGW
121. Download sources from https://www.cryptopp.com/. You should use the latest version.
13Now it is: https://github.com/weidai11/cryptopp/releases/tag/CRYPTOPP_7_0_0
142. Download MSYS 2. This is windows shell that emulates Linux commands. Install it.
153. Extract cryptopp to any place
164. Run MSYS2
175. Go into the extracted dir
186. Set path to your compiler "export PATH=$PATH:/path/to/qt/dir/Tools/mingw530_32/bin"
197. Compile library: "make libcryptopp.a" for static library
208. Install libraries and headers "make install PREFIX=$PWD/installed"
219. Copy library and headers from install folder to deps folder
22
23
24FileCrypter module
25Just copy FileCrypter folder to your project folder. Add to your project .pro file:
26include(FileCrypter/FileCrypter.pri)
27
28And link libraries:
29LIBS += -L$$PWD/path/to/dir/with/lib -lcryptopp
30
31And include library headers:
32INCLUDEPATH += $$PWD/path/to/include
33INCLUDEPATH += $$PWD/path/to/include
34
35That's all.
36
37FileCrypter architecture:
38The module consist from few logical modules:
39ThreadedCrypter - wrapper for running encryption/decryption in dedicated thread
40BaseCrypter(FileCrypter/FileDecrypted) - calculating hashes, interaction with database
41FileProcessor(Encrypter/Decrypter) - encrypt and decrypt files.
42
43So architecture is:
44ThreadedCrypter --> BaseCrypter(FileCrypter/FileDecrypter) --> FileProcessor(Crypter/Decrypter)
45
46
47FileProcessor folder
48FileProcessor class open in and out files. Passes input file to the child and write a result to the output file.
49Also, it tracks the progress:
50- sigError(const QString &error). Fired if any error occurred
51- sigFinished(). Fired if file successfully processed
52- sigChunkProcessed(qin64 chunk, qint64 total). Fired after each chunk. Where "chunk" is current chunk num. And "total" is the total amount of chunks.
53
54Encryptor class read a chunk from a file. Encrypt it and return to parent.
55This class doesn't need any key or iv. It will be generated automatically.
56
57Decryptor class read a chunk from a file. Decrypt it and return to parent.
58This class required key and iv for decryption.
59
60You can use it in this way:
61
62Encryptor enc{"in.txt", "crypted.txt"};
63enc.process();
64QDebug() << "File" << enc.getIn() << "encrypted with key" << enc.getKey() << "and iv" <<enc.getIv();
65
66Same for Decryptor.
67
68FileDatabase folder
69FileDatabase class create or open database. Also, create table if not exists.
70Methods:
71- insert(fileHash, fileName, encryptionKey, encryptionIv)
72Inserts new record to table
73
74- exist(fileHash)
75Checks if hash already exists
76
77- get(fileHash)
78Returns record with hash, name, key and iv
79
80
81Utils folder:
82A simple wrapper around cryptopp functions.
83
84BaseCrypter folder.
85A skeleton for encryption, decryption or any other tasks.
86All children should implement pure virtual methods:
87
88FileProcessor *makeProcessor();
89The child should return working file processor.
90
91onFileProcessed();
92The child can do any other tasks here. Like calculating output file hash and other.
93
94So you should put your algorithm inside makeProcessor() and onFileProcessed() methods.
95
96FileCrypter is a child of BaseCrypter. The class encrypting the file and add a record with info inside the database.
97FileDecrypter is a child of BaseCrypter. The class search key and iv in the database and decrypts file.
98
99Usage:
100FileCrypter crypter{"in.txt", "database.db"};
101crypter.start();
102
103QObject::connect(&crypter, &BaseCrypter::sigFinished, [](){
104 qDebug() << "File encrypted!"
105});
106
107ThreadedCrypter class is a wrapper for FileCrypter and FileDecrypter.
108It has thread pool where a file will be encrypted or decrypted.
109Usage:
110
111ThreadedCrypter crypter{"database.db"};
112crypter.encrypt("in.txt");
113crypter.decrypt("encryptedFile");