MCPcopy Create free account
hub / github.com/altairwei/WizNotePlus / encryptDataToFile

Method encryptDataToFile

src/share/WizZiwReader.cpp:205–242  ·  view source on GitHub ↗

encrypt note decrypted before

Source from the content-addressed store, hash-verified

203
204// encrypt note decrypted before
205bool WizZiwReader::encryptDataToFile(const QByteArray& sourceData, \
206 const QString& destFileName)
207{
208 //random password
209 QString ziwPassword = WizGenGUIDLowerCaseLetterOnly() + WizGenGUIDLowerCaseLetterOnly();
210 //
211 // encrypt data
212 QByteArray outBytes;
213 if (!WizAESEncryptToString((const unsigned char *)(ziwPassword.toUtf8().constData()), sourceData, outBytes)) {
214 return false;
215 }
216
217 WIZZIWHEADER header;
218 initZiwHeader(header, ziwPassword);
219
220 QFile destFile(destFileName);
221 if (!destFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
222 TOLOG("Can't open dest file while encrypt to temp file");
223 return false;
224 }
225
226 QDataStream out(&destFile);
227 if (sizeof(header) != out.writeRawData((const char *)&header, sizeof(header))) {
228 TOLOG("Write data failed while encrypt to temp file");
229 destFile.remove();
230 return false;
231 }
232
233 if (outBytes.length() != out.writeRawData(outBytes.constData(), outBytes.length())) {
234 TOLOG("Write data failed while encrypt to temp file");
235 destFile.remove();
236 return false;
237 }
238
239 destFile.close();
240
241 return true;
242}
243
244
245bool WizZiwReader::encryptFileToFile(const QString& sourceFileName, \

Callers 1

createDocumentAndInitMethod · 0.80

Calls 7

WizAESEncryptToStringFunction · 0.85
TOLOGFunction · 0.85
lengthMethod · 0.80
openMethod · 0.45
removeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected