From 64d216fcf2b26cabb76cf66b100a71a4afb8636f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lie=20Delhaie?= Date: Tue, 8 Feb 2022 17:59:05 +0100 Subject: [PATCH] Ecnryptable note --- TaskNote.pro | 10 +- TaskNote.pro.user | 143 +++++++++--------- icons.qrc | 11 +- .../outline_add_circle_outline_black_18dp.png | Bin 208 -> 0 bytes .../outline_add_circle_outline_black_48dp.png | Bin 0 -> 885 bytes .../outline_delete_forever_black_18dp.png | Bin 183 -> 0 bytes .../outline_delete_forever_black_48dp.png | Bin 0 -> 490 bytes resources/outline_help_outline_black_18dp.png | Bin 271 -> 0 bytes resources/outline_help_outline_black_48dp.png | Bin 0 -> 1297 bytes resources/outline_lock_black_48dp.png | Bin 0 -> 620 bytes resources/outline_lock_open_black_48dp.png | Bin 0 -> 620 bytes resources/outline_save_black_18dp.png | Bin 191 -> 0 bytes resources/outline_save_black_48dp.png | Bin 0 -> 468 bytes resources/outline_shield_black_48dp.png | Bin 0 -> 963 bytes src/frames/aboutdialog.ui | 2 +- src/frames/mainwindow.cpp | 23 ++- src/frames/mainwindow.h | 1 + src/frames/mainwindow.ui | 59 +++++++- src/models/note.cpp | 107 ++++++++++++- src/models/note.h | 25 +++ src/services/savemanager.cpp | 4 + 21 files changed, 294 insertions(+), 91 deletions(-) delete mode 100755 resources/outline_add_circle_outline_black_18dp.png create mode 100644 resources/outline_add_circle_outline_black_48dp.png delete mode 100755 resources/outline_delete_forever_black_18dp.png create mode 100644 resources/outline_delete_forever_black_48dp.png delete mode 100755 resources/outline_help_outline_black_18dp.png create mode 100644 resources/outline_help_outline_black_48dp.png create mode 100644 resources/outline_lock_black_48dp.png create mode 100644 resources/outline_lock_open_black_48dp.png delete mode 100755 resources/outline_save_black_18dp.png create mode 100644 resources/outline_save_black_48dp.png create mode 100644 resources/outline_shield_black_48dp.png diff --git a/TaskNote.pro b/TaskNote.pro index cf05ddd..9443911 100755 --- a/TaskNote.pro +++ b/TaskNote.pro @@ -19,7 +19,7 @@ win32 { QMAKE_CXXFLAGS_RELEASE += -favor:INTEL64 } RC_ICONS = icon.ico - VERSION = 1.1.0.0 + VERSION = 1.2.0.0 QMAKE_TARGET_COMPANY = "Aurelie Delhaie" QMAKE_TARGET_PRODUCT = "TaskNote" QMAKE_TARGET_DESCRIPTION = "TaskNote" @@ -37,14 +37,18 @@ macx { message("CPU Architecture : aarch64") QMAKE_CXXFLAGS_RELEASE += -mcpu=apple-a14 } - VERSION = 1.1.0 + VERSION = 1.2.0 } linux-g++* { message("Build for Linux") + + LIBS += -L/usr/lib/crypto++ -lcrypto++ + INCS += -I/usr/include/crypto++ + QMAKE_CXXFLAGS_RELEASE *= -O3 QMAKE_CXXFLAGS_RELEASE += -march=skylake - VERSION = 1.1.0 + VERSION = 1.2.0 } # You can make your code fail to compile if it uses deprecated APIs. diff --git a/TaskNote.pro.user b/TaskNote.pro.user index 97c2f07..d162e94 100755 --- a/TaskNote.pro.user +++ b/TaskNote.pro.user @@ -1,14 +1,14 @@ - + EnvironmentId - {f1407b1e-b4d5-4aac-ba0d-b38072a0dfb8} + {23c6a5b6-2840-4c04-84d4-91387dc9bb9f} ProjectExplorer.Project.ActiveTarget - 0 + 0 ProjectExplorer.Project.EditorSettings @@ -28,7 +28,7 @@ QmlJSGlobal - 2 + 2 UTF-8 false 4 @@ -77,7 +77,7 @@ true true Builtin.DefaultTidyAndClazy - 4 + 8 @@ -89,30 +89,28 @@ ProjectExplorer.Project.Target.0 Desktop - Qt 6.2.0 for macOS - Qt 6.2.0 for macOS - qt.qt6.620.clang_64_kit - 1 - 0 - 0 + Desktop Qt 6.2.3 GCC 64bit + Desktop Qt 6.2.3 GCC 64bit + qt.qt6.623.gcc_64_kit + 0 + 0 + 0 0 - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Debug - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Debug + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Debug + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Debug true QtProjectManager.QMakeBuildStep false - - arm-darwin-generic-mach_o-64bit - + true Qt4ProjectManager.MakeStep - 2 + 2 Build Build ProjectExplorer.BuildSteps.Build @@ -123,7 +121,7 @@ Qt4ProjectManager.MakeStep clean - 1 + 1 Clean Clean ProjectExplorer.BuildSteps.Clean @@ -131,56 +129,15 @@ 2 false + false Debug Qt4ProjectManager.Qt4BuildConfiguration 2 - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Release - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Release - - - true - QtProjectManager.QMakeBuildStep - false - - arm-darwin-generic-mach_o-64bit - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Profile - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Profile + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Release + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Release true @@ -192,7 +149,7 @@ true Qt4ProjectManager.MakeStep - 2 + 2 Build Build ProjectExplorer.BuildSteps.Build @@ -203,7 +160,7 @@ Qt4ProjectManager.MakeStep clean - 1 + 1 Clean Clean ProjectExplorer.BuildSteps.Clean @@ -211,6 +168,48 @@ 2 false + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Profile + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + true + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false Profile Qt4ProjectManager.Qt4BuildConfiguration @@ -218,10 +217,10 @@ 0 0 - 3 + 3 - 0 + 0 Deploy Deploy ProjectExplorer.BuildSteps.Deploy @@ -231,7 +230,7 @@ false ProjectExplorer.DefaultDeployConfiguration - 1 + 1 true true @@ -239,21 +238,21 @@ 2 - Qt4ProjectManager.Qt4RunConfiguration:/Users/alexis/TaskNote/TaskNote.pro - /Users/alexis/TaskNote/TaskNote.pro + Qt4ProjectManager.Qt4RunConfiguration:/home/aurelie/src/TaskNote/TaskNote.pro + /home/aurelie/src/TaskNote/TaskNote.pro false true true false true - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Release/TaskNote.app/Contents/MacOS + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Debug - 1 + 1 ProjectExplorer.Project.TargetCount - 1 + 1 ProjectExplorer.Project.Updater.FileVersion diff --git a/icons.qrc b/icons.qrc index c5e844d..a1df688 100755 --- a/icons.qrc +++ b/icons.qrc @@ -1,9 +1,12 @@ - resources/outline_add_circle_outline_black_18dp.png - resources/outline_delete_forever_black_18dp.png - resources/outline_save_black_18dp.png - resources/outline_help_outline_black_18dp.png + resources/outline_add_circle_outline_black_48dp.png + resources/outline_delete_forever_black_48dp.png + resources/outline_help_outline_black_48dp.png + resources/outline_lock_black_48dp.png + resources/outline_save_black_48dp.png + resources/outline_shield_black_48dp.png + resources/outline_lock_open_black_48dp.png resources/logo.png diff --git a/resources/outline_add_circle_outline_black_18dp.png b/resources/outline_add_circle_outline_black_18dp.png deleted file mode 100755 index 59e2fa29726d2c858b06d03bfe4c7dd4866189c7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 208 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+0wn(&ce?|mrhB?LhG?9hI%y|wivy2qJfjR} zsK7)=*$bQ^Mwe7B^hVEYm~&&Ic|!S?H5X3ZILSYczgAk#{pgWHhg?eeO>#88`K2!Y z=^7>Em9k(#g2Ez|TiMf(_?2tEzTtWQZkUO3;{?OhzY3;aXIPt3WCLFX_euQKy^`Fs ze2$@)f&vFSdy_zeP;wo^&SN{p$|E0`TrL%R-Z*#tC-u176N6c04^>11oyg$n>gTe~ HDWM4f30qDH diff --git a/resources/outline_add_circle_outline_black_48dp.png b/resources/outline_add_circle_outline_black_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..c6ecf98ef7e1f21dad37ca0b4f7ae1b0457d5ac3 GIT binary patch literal 885 zcmV-*1B(2KP)pv2(sAz!4)t1If=<&`GIq^W19aOIhLce$cMCaFPFRu3p__cze9&-7NRBJ&z2*JNA{_+#1uKk z02m|36id|E=h4xAi~gwS4{`Kk)yJ$;aP(4Oo#P+<95ECH{c$dAt9+wD-jlaH4c=`1 zT`(Rt{Yh?YDtlqmXLw++$%~EG8z#eTeLMQQj0EyL!mh1^(0XBrb8QvvkV1hXZLRMK(HqY0S3w1sLLq~EXk<6S^i zv+ieO5s=mV7ph+A4{&Q4{oa0C{slnMG81kY@Ft+52^xq^0Ga@!;>EnrvQ>X!G*$tl zmN4&%KKJG`mg?)C=TI;KP`7xPac|tT#QR3<0u0N3q3M1BRlBd@V;K%A02-EI>~b+J zSt`#bA|P+^QSzt!1QHPdC;mo)dPKXHn1D6Qv9Jpa^Qo8>5))8Re0(zOY&5GFJ$PAv zLl)4-gW_e@*=R*E*@MIcz@Fk|#o1&>G1*8|z=q;w$JyjiFGvi?KY%bH z{0WK)(T{*k2!DoULi9tpe-Qi>v3o!Xehk_TvCnZ+q)3q>g-rYfanVNP4)knF00000 LNkvXXu0mjfyC$fY literal 0 HcmV?d00001 diff --git a/resources/outline_delete_forever_black_18dp.png b/resources/outline_delete_forever_black_18dp.png deleted file mode 100755 index c89a0fffca858ea92c62df9f9f3a8e833ea2d6c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 183 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+0wn(&ce?|m>O5T>Lp07OCoJGKNV;))gFMG~ zrpSl}=EL&^BGI3jXnUa|MfHE9QiQ0X!G@-r3PQ`3!rON9 zymF}MKPb6fiMQ=J&-nuZvhz#p64w8IxY0z>%r3ghtU6vpHKgMtZsNk9S;kbnfZ1QbOHGngeH0SQPz0&xkj zJx>A>kief_nDpMCFbiZTkUH1OJ4KX$(B$%L=*Z z!6%x9Rvij%e5!R|h0j41|2aO{O8hiHp^Z;h3q9gv6h2`!x^yU9;!~E>OY6Y3<5LP` zaSL?eN798{_z?`^K78_NbO=82Le^FDL{dt0muyiKb8blbaymiL(@p3%G%1cfa}D*D z@>0RJU{P=C+Y0uQf&5sdQRu>_KiH}j3I{&@(c%>x?&|-51SAlFKt75!{Psog&cPJvlLQq^Eu@v66irTelW z&3492GXKmxd1m-`^vtcT&GqgB16x6?GT0h4kxVHlOm%cj6@pTBJEe4zV`ynuDy;RLFFcHlz&`Q)z6h8X!4!WY% zJt*^O@1Y6R>)_4zRY$t677kCIf9pheZ2|1;s_Mpq)Jzr@71A)X)md5|xaF(-5kDBc VQPsf?nmqsj002ovPDHLkV1inHaCHCx diff --git a/resources/outline_help_outline_black_48dp.png b/resources/outline_help_outline_black_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..50895841ef12ca00670b38dea8030cb33c83c652 GIT binary patch literal 1297 zcmV+s1@8KZP)NyTiy$d%!cgSUSmiJjn;W#AqS% zh^0IhLX4)y^h`)nK5*YeJH%EyyqWUBoS^JkUo{WlVZ`3UIADH7EptPRJG&Rx!KVbh zP{fy*i><$zi!V_`FC_5kI_x!`R71)+y|BUf;}3>wN1=!<5Th+9;wZQ_*mw{&lxy1J zP0JbLapu>ffNc;*+fYEg$CY5Y!rv^%tfm+|>~Yrr2q}>tJ+6j_AqM@?C^g6YfM-QV zEQOTVQgjS>wa-U$1n+L+dwx5|Gk+;0kfn}SLObLCgu4;6dMq>C_w$b1{t*(`kB-lT zyy1DU4D|@sO{VDuw+fI(Qh-Y@LKHV4NL83;m{>a!X*)W_+s<^{gLBa8H|O9UOt-%s zF=qOXG)&;lLlsKir2)^Zu@J=`+<_YWUp2S`dmxIj0k70cQSzQP%;)Ejw#0B&?M6>n z>xtclt2IH|a)$MUrvtotsz1^&xYQe>xD#o+6Qbx1mxdV*ZgZ5Z0T9J`aH(jx=hq-@ zHHK$G(PL#z6a(O&@rX}=YhQZ2Tl@ZJ`4X;8u-*~;(?68GAFj<(wtX&KJ6GBEEVy>R z{y}hQYQTPFu#Rv|o8@c`*IKKyrtWoAw!I$>@UEva&>B=B##$-+z8$VrVU4o=p78E= zWsuhpYaP`EcE4UzwtqXk8?6lT1Y+$`W#8X|PfsY@9}Vw5Q3kmZF_y!6W#4awPgg42 z{{-GmQ3mOb*h&m1&K9(VPu-OXh7ZFoM8NFR(eW+F`1eA9`);rWndp}!1MJIn zFc)%3GR{SL|5hpcavIDw`t%1`axF%bX&2m>+yuCdUC%knY6 zz)H*KVU|Y^v;1iy=T8&;aW3VLbNzWb=g-r9Kw~n@-}!)sk0|*C_=u7Z>G=itke-jJ z`UUuyst;=W1^A%0uPX2h@KpuAtivzBmv#8M8nysmSF@|INvpEVtF+Inw$iJ()vLPL ztGt`5z8>g-1JDZ-peH^+Z>)eGxdFX0OwT-fXPYERk|e(lu!<;82WFK100000NkvXX Hu0mjfX#i!H literal 0 HcmV?d00001 diff --git a/resources/outline_lock_black_48dp.png b/resources/outline_lock_black_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..4817e2eae3041c69d838eb51eed49f39891f557e GIT binary patch literal 620 zcmV-y0+aoTP)Z1 zc5HTb&CIl(VQT_?CH?`8;R!SD$t|Id|b)LjDGGYwt&;DkJMzn6u#?pl_|? zS?Ss{tG4eRU}&vkw{&gSx_d+S0Mm?w>q^zvnd+%~fTxUvqe|6Bnd&F^0NECHP^tRB zYG=+P+XHqgRqt56zM4Te!Odw(egux#R4h{fa^3~_ycnJB=lK0qQ0kjOVI@&8i* z1yBG5Pyhu`00j{E!PG-n^|)RD*dDsP$Mpc9$U~R&xE=tEYI$67fZsfH8ILOt5ZCm$ z;sCRn9#e%vPbfu|OXoCQDh_tWDBId-X`p`oGC*7yXEkr?1rWWo0U0000vLo}Oc>CjX21AL?%ALca>G5B_KI&Z z;v-Rfm>-O2+9LD zwEVA)WH`DB!d5(U%M~6TSKRWc!}40 zOk*lW=DM!lwjK@~7iv7jv^GQC`7UPl51)2wF?Zq4g!~iM+TQn4ReIX9u;!$EfR?t7 z{nWL6t+rJ@z(8BYdg|J`cJ~J5156?ko-$QGMXD#|1I!~5+L@}`k?MK*0MQn9ovHd- zYiFfLvS@<*=u*B!4Sn;Pkvj21G-*e9+ zr^U&CD^+}$Z$%*tjmTFhhQ;jty)l4&5zm5eOuj0d2zo0000lzgFJ6u zdVoXdmU$0t+ZKK2`5rj6kwsSG)x-r%&5DPmLsAu7zw-Q_xPUp}ia^G#GN&$uM-^)i zui}tCuu!Azp{BsG2f-@mJ_x^AG~YqY&-GV9`|HPHN6r**t$89cq4l`$9iB{w6TN4B qZ!BUJGJXBg-GE~q`>6m?28Ky@(sO;&wJ!l(#Ng@b=d#Wzp$PzbB}%CP diff --git a/resources/outline_save_black_48dp.png b/resources/outline_save_black_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..bbda264e78d8ddd3b8f2a63b77fbcc6dfd03b7dd GIT binary patch literal 468 zcmV;_0W1EAP)2`k0HBSI*H zl<$$y1Os>?v;hHL2=_lJl_kDq2wDI!f*wGKpa~Emi~)R2Q*nYez&k-7;F%Bt;FS;t zFiwaDFh+<7FieOF04!q%fB*srAbeGmR=UfcJUpfc_Pf z;pY=CbC)vROF+Ye=VN~Px4EEm4eN2?JYqL*>@y6*Fbu=|m;3I(9RA*uz+RzQR2TnHhPQZ6p-Uz2A{7~V5VTu$^biJh7b?0$NSCf1EhsF~Jed~@ zPj=`a;vbR@4;4hs6it2oUP#5v?3sIPl;& zy77fdH!bZm96%fTv5EX%*`&2L+PW{0K`-Y2HvRuHPrqd1ADO(S#4=K1WOOA~k@Aj= zu0$Rwf02o0q)a0dt4Nte<|CEZM9M5Ov*WOVQoDK-QCBU4(W7z_l9OwdSKH&9As z{6xyoK*EOs(;B7zVMcn%{eIu-3^)VMfHU9>I0MdrGvEw31I~am;Eml-EhjbV0Sx>U z)(^58IH*w%U|?Ok@#aKIqi*2{RI(bVw0{Jag!O7x12r1;00zDZ>$R)~YBlN>4Aiq4 zsOLA(#A=|?zJafy8fem}2f!h03r{Qg&Vo8YX`9q7bfXi(mP>2~MCJ(_-6${?nSn7o zwC%!yU11tdq_8R|wc8=CkY2EMvKY7_y=<+pMLjG~zh^NpAgB!6qwbP=hf~&@e_HD8 zy6llxVM8GAwQk^t{!aWiz(Wtfs=TCFf&mw2a0jR75!&>W6f=;6Lgyd7L)l~GCR zP05^ZCC*X4(fT>;NOE^dV!SKy?T`v1o=bwia5*sBRq5)RCk0j<#*8Gnf^@*!$5n}I zh7_2QRm5lkXN`H%SX9I(ixBWoF{@|MaC%;&qWO7Z4h2aJD#TYQ(SFg29}0%S@Sc@d zDK2V-LH0c#brZO+ICTpbuPTIyGsr1txP8EhqV-NijGdL9Z!-pZN9RnoMqqsWj$_~|v(L2&+Od2(Rl4`^Z<#>!OUya|Q zJqb)4&H~FS=m*E1gp^cW_ lVE~_~*Ku%gaBy(2j^AuQwqo9K2WbER002ovPDHLkV1m1Dxl8~6 literal 0 HcmV?d00001 diff --git a/src/frames/aboutdialog.ui b/src/frames/aboutdialog.ui index 9565d03..4e04184 100755 --- a/src/frames/aboutdialog.ui +++ b/src/frames/aboutdialog.ui @@ -71,7 +71,7 @@ - Version 1.1.0.0 + Version 1.2.0.0 Qt::AlignCenter diff --git a/src/frames/mainwindow.cpp b/src/frames/mainwindow.cpp index 0bdcd15..2b17b1f 100755 --- a/src/frames/mainwindow.cpp +++ b/src/frames/mainwindow.cpp @@ -14,6 +14,7 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->noteList, &QListWidget::currentRowChanged, this, &MainWindow::selectionChanged); connect(ui->titleEdit, &QLineEdit::textChanged, this, &MainWindow::titleChanged); connect(ui->contentEdit, &QPlainTextEdit::textChanged, this, &MainWindow::contentChanged); + connect(ui->actionEncrypt, &QAction::triggered, this, &MainWindow::encryptNote); const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); ui->contentEdit->setFont(fixedFont); this->savemng = new SaveManager(); @@ -55,8 +56,13 @@ void MainWindow::selectionChanged(int i) ui->titleEdit->setDisabled(false); ui->contentEdit->setDisabled(false); ui->titleEdit->setText(n->getTitle()); - ui->contentEdit->setPlainText(n->getContent()); - ui->markdownViewer->setMarkdown(n->getContent()); + if (n->isEncrypted()) + { + ui->contentEdit->setPlainText(n->getEncryptedContent("azertyuiop")); + } else { + ui->contentEdit->setPlainText(n->getContent()); + } + ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText()); } void MainWindow::removeSelected() @@ -71,6 +77,7 @@ void MainWindow::removeSelected() void MainWindow::save() { + ui->actionSave->setDisabled(true); if (this->currentIndex > -1) { Note *n = this->savemng->getNoteByIndex(this->currentIndex); @@ -89,6 +96,7 @@ void MainWindow::titleChanged() n->setTitle(ui->titleEdit->text()); ui->noteList->item(this->currentIndex)->setText(ui->titleEdit->text()); } + ui->actionSave->setDisabled(false); timer->start(1000); } @@ -99,6 +107,16 @@ void MainWindow::showAboutBox() dialog.exec(); } +void MainWindow::encryptNote() +{ + if (this->currentIndex > -1) + { + Note *n = this->savemng->getNoteByIndex(this->currentIndex); + n->encrypt("azertyuiop"); + savemng->flushSave(); + } +} + void MainWindow::contentChanged() { timer->stop(); @@ -108,6 +126,7 @@ void MainWindow::contentChanged() n->setContent(ui->contentEdit->toPlainText()); ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText()); } + ui->actionSave->setDisabled(false); timer->start(1000); } diff --git a/src/frames/mainwindow.h b/src/frames/mainwindow.h index 644b7a9..0f9d008 100755 --- a/src/frames/mainwindow.h +++ b/src/frames/mainwindow.h @@ -30,6 +30,7 @@ private slots: void contentChanged(); void titleChanged(); void showAboutBox(); + void encryptNote(); private: Ui::MainWindow *ui; diff --git a/src/frames/mainwindow.ui b/src/frames/mainwindow.ui index 49e7fb4..ce9b996 100755 --- a/src/frames/mainwindow.ui +++ b/src/frames/mainwindow.ui @@ -120,15 +120,24 @@ + + true + 16777215 - 33 + 96 toolBar + + false + + + Qt::ToolButtonTextUnderIcon + TopToolBarArea @@ -140,12 +149,16 @@ + + + + - :/icon/resources/outline_add_circle_outline_black_18dp.png:/icon/resources/outline_add_circle_outline_black_18dp.png + :/icon/resources/outline_add_circle_outline_black_48dp.png:/icon/resources/outline_add_circle_outline_black_48dp.png Add @@ -157,16 +170,19 @@ - :/icon/resources/outline_delete_forever_black_18dp.png:/icon/resources/outline_delete_forever_black_18dp.png + :/icon/resources/outline_delete_forever_black_48dp.png:/icon/resources/outline_delete_forever_black_48dp.png Remove + + false + - :/icon/resources/outline_save_black_18dp.png:/icon/resources/outline_save_black_18dp.png + :/icon/resources/outline_save_black_48dp.png:/icon/resources/outline_save_black_48dp.png Save @@ -175,12 +191,45 @@ - :/icon/resources/outline_help_outline_black_18dp.png:/icon/resources/outline_help_outline_black_18dp.png + :/icon/resources/outline_help_outline_black_48dp.png:/icon/resources/outline_help_outline_black_48dp.png About + + + + :/icon/resources/outline_lock_black_48dp.png:/icon/resources/outline_lock_black_48dp.png + + + Lock + + + false + + + + + + :/icon/resources/outline_lock_open_black_48dp.png:/icon/resources/outline_lock_open_black_48dp.png + + + Unlock + + + false + + + + + + :/icon/resources/outline_shield_black_48dp.png:/icon/resources/outline_shield_black_48dp.png + + + Encrypt + + diff --git a/src/models/note.cpp b/src/models/note.cpp index 7200a04..59be5be 100755 --- a/src/models/note.cpp +++ b/src/models/note.cpp @@ -2,27 +2,35 @@ Note::Note() { - + QUuid uid = QUuid::createUuid(); + this->uuid = uid.toString(QUuid::StringFormat::WithoutBraces); } QJsonObject Note::toJson() { QJsonObject o; - + o["uuid"] = this->uuid; o["title"] = this->title; o["content"] = this->content; - + o["encrypted"] = this->encrypted; return o; } Note *Note::fromJson(QJsonObject o) { Note *n = new Note(); + n->uuid = o["uuid"].toString(n->uuid); n->title = o["title"].toString(); n->content = o["content"].toString(); + n->encrypted = o["encrypted"].toBool(false); return n; } +QString Note::getUuid() +{ + return uuid; +} + QString Note::getTitle() { return title; @@ -30,7 +38,47 @@ QString Note::getTitle() QString Note::getContent() { - return content; + if (!this->encrypted) + { + return content; + } + return ""; +} + +QString Note::getEncryptedContent(QString passwd) +{ + if (this->encrypted) + { + using namespace CryptoPP; + std::string password = passwd.toStdString(); + QString bytes = QByteArray::fromBase64(QByteArray::fromStdString(this->content.toStdString())); + std::string encoded = bytes.toStdString(); + std::string iv = encoded.substr(0, TAG_SIZE); + std::string cipher = encoded.substr(TAG_SIZE + 1, encoded.length()); + std::string recovered; + + try { + GCM< AES >::Decryption d; + d.SetKeyWithIV((const unsigned char*)password.c_str(), sizeof(password.c_str()), (const unsigned char*)iv.c_str(), sizeof(iv.c_str())); + + AuthenticatedDecryptionFilter df( d, + new StringSink(recovered), + AuthenticatedDecryptionFilter::DEFAULT_FLAGS, TAG_SIZE + ); + StringSource ss2(cipher, true, + new Redirector(df) + ); + return QString::fromStdString(recovered); + } catch (CryptoPP::Exception& e) { + std::cout << e.GetWhat() << "\n"; + } + } + return ""; +} + +bool Note::isEncrypted() +{ + return this->encrypted; } void Note::setTitle(QString value) @@ -40,6 +88,57 @@ void Note::setTitle(QString value) void Note::setContent(QString value) { + if (!this->encrypted) { this->content = value; + } +} + +// TODO encrypt avec le mot de passe +bool Note::setEncryptedContent(QString value, QString passwd) +{ + if (this->encrypted) { + using namespace CryptoPP; + AutoSeededRandomPool prng; + std::string password = passwd.toStdString(); + std::string pdata = value.toStdString(); + std::string cipher, encoded; + + SecByteBlock key(AES::MAX_KEYLENGTH + AES::BLOCKSIZE); + SecByteBlock iv(AES::BLOCKSIZE); + prng.GenerateBlock(iv, iv.size()); + try + { + GCM::Encryption e; + e.SetKeyWithIV(key, sizeof(key), iv, sizeof(iv)); + + StringSource ss1(pdata, true, + new AuthenticatedEncryptionFilter(e, + new StringSink(cipher), false, TAG_SIZE + ) + ); + std::string s(reinterpret_cast< char const* >(iv.data())) ; + encoded = s + cipher; + auto bytes = QByteArray::fromStdString(encoded); + this->content = bytes.toBase64(); + return true; + } + catch(CryptoPP::Exception& e) + { + std::cout << e.GetWhat() << "\n"; + return false; + } + } + return false; +} + +void Note::encrypt(QString password) +{ + if (!this->encrypted && (password.length() >= 6)) { + this->encrypted = true; + if (!setEncryptedContent(this->content, password)) + { + this->encrypted = false; + } + } } diff --git a/src/models/note.h b/src/models/note.h index a22a546..ee4aa47 100755 --- a/src/models/note.h +++ b/src/models/note.h @@ -1,8 +1,25 @@ #ifndef NOTE_H #define NOTE_H +#define TAG_SIZE 12 + +#include +#include + #include #include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include class Note { @@ -12,15 +29,23 @@ public: QJsonObject toJson(); static Note* fromJson(QJsonObject o); + QString getUuid(); QString getTitle(); QString getContent(); + QString getEncryptedContent(QString passwd); + bool isEncrypted(); void setTitle(QString value); void setContent(QString value); + bool setEncryptedContent(QString value, QString passwd); + + void encrypt(QString password); private: + QString uuid; QString title; QString content; + bool encrypted; }; #endif // NOTE_H diff --git a/src/services/savemanager.cpp b/src/services/savemanager.cpp index 63d7787..27a4884 100755 --- a/src/services/savemanager.cpp +++ b/src/services/savemanager.cpp @@ -8,6 +8,10 @@ SaveManager::SaveManager() SaveManager::~SaveManager() { flushSave(); + foreach (Note *n, notes) + { + delete n; + } } void SaveManager::flushSave()