mirror of
https://github.com/QuasarApp/Qt-Secret.git
synced 2025-04-29 00:54:31 +00:00
some problems with encrypt/decrypt
This commit is contained in:
parent
cb77b890d1
commit
40ef900252
@ -1,5 +1,8 @@
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import "modules/"
|
||||
|
||||
Item {
|
||||
|
||||
id: parentItem
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import QtQuick.Layouts 1.12
|
||||
import "modules/"
|
||||
|
||||
Item {
|
||||
|
||||
id: parentItem
|
||||
|
||||
Connections {
|
||||
@ -21,34 +20,43 @@ Item {
|
||||
anchors.rightMargin: 20
|
||||
|
||||
function changeState() {
|
||||
keyLabledText.labelText = (encryptDecryptMenu.encryptState ? qsTr("Public key:") : qsTr("Private key:"))
|
||||
inputText.labelText = (encryptDecryptMenu.encryptState ? qsTr("Text to encrypt:") : qsTr("Text to decrypt:"))
|
||||
outputText.labelText = (encryptDecryptMenu.encryptState ? qsTr("Encrypted text:") : qsTr("Decrypted text:"))
|
||||
keyLabledText.labelText = (encryptDecryptMenu.state ? qsTr("Public key:") : qsTr("Private key:"))
|
||||
inputText.labelText = (encryptDecryptMenu.state ? qsTr("Text to encrypt:") : qsTr("Text to decrypt:"))
|
||||
outputText.labelText = (encryptDecryptMenu.state ? qsTr("Encrypted text:") : qsTr("Decrypted text:"))
|
||||
}
|
||||
|
||||
EncryptDecryptMenu {
|
||||
id: encryptDecryptMenu
|
||||
verticalSize: 0.1
|
||||
firstStateName: qsTr("Encrypt")
|
||||
secondStateName: qsTr("Decrypt")
|
||||
onChangeState: column.changeState()
|
||||
onGetEncrypDecrypt: appCore.getEncryptDecrypt(encryptDecryptMenu.encryptState, keyLabledText.textAreaText, inputText.textAreaText)
|
||||
onGetEncrypDecrypt: appCore.getEncryptDecrypt(encryptDecryptMenu.state,
|
||||
keyLabledText.textAreaText,
|
||||
inputText.textAreaText)
|
||||
}
|
||||
|
||||
LabledText {
|
||||
RowElement {
|
||||
id: keyLabledText
|
||||
verticalSize: 0.4
|
||||
labelText: qsTr("Public key:")
|
||||
buttonImageSource: "../images/clear.png"
|
||||
onButtonClicked: keyLabledText.setText("")
|
||||
}
|
||||
|
||||
LabledText {
|
||||
RowElement {
|
||||
id: inputText
|
||||
verticalSize: 0.4
|
||||
labelText: qsTr("Text to encrypt:")
|
||||
buttonImageSource: "../images/clear.png"
|
||||
onButtonClicked: inputText.setText("")
|
||||
}
|
||||
|
||||
RowElement {
|
||||
id: outputText
|
||||
verticalSize: 0.4
|
||||
labelText: qsTr("Encrypted text:")
|
||||
buttonImageSource: "../images/cpy.png"
|
||||
onButtonClicked: appCore.copyToClipboard(outputText.textAreaText)
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,14 @@ import QtQuick.Layouts 1.12
|
||||
import "modules/"
|
||||
|
||||
Item {
|
||||
|
||||
id: parentItem
|
||||
|
||||
Connections {
|
||||
|
||||
target: appCore
|
||||
onQmlShowKeys: {
|
||||
secondRow.setText(privKey)
|
||||
thirdRow.setText(pubKey)
|
||||
publicKeyRow.setText(pubKey)
|
||||
privateKeyRow.setText(privKey)
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,16 +29,18 @@ Item {
|
||||
}
|
||||
|
||||
RowElement {
|
||||
id: secondRow
|
||||
labelText: qsTr("Private key:")
|
||||
onButtonClicked: appCore.copyToClipboard(secondRow.textAreaText)
|
||||
id: publicKeyRow
|
||||
labelText: qsTr("Public key:")
|
||||
buttonImageSource: "../images/cpy.png"
|
||||
onButtonClicked: appCore.copyToClipboard(publicKeyRow.textAreaText)
|
||||
}
|
||||
|
||||
RowElement {
|
||||
id: thirdRow
|
||||
id: privateKeyRow
|
||||
Layout.leftMargin: 8
|
||||
labelText: qsTr("Public key:")
|
||||
onButtonClicked: appCore.copyToClipboard(thirdRow.textAreaText)
|
||||
labelText: qsTr("Private key:")
|
||||
buttonImageSource: "../images/cpy.png"
|
||||
onButtonClicked: appCore.copyToClipboard(privateKeyRow.textAreaText)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,21 +37,20 @@ void AppCore::copyToClipboard(QString text) {
|
||||
|
||||
void AppCore::getEncryptDecrypt(bool actionType, QString key, QString message)
|
||||
{
|
||||
emit qmlOpenPopup();
|
||||
|
||||
// encryption
|
||||
if(actionType) {
|
||||
emit qmlOpenPopup();
|
||||
emit wrkEncryptMessage(key.toUtf8(), message.toUtf8());
|
||||
emit wrkEncryptMessage(key, message);
|
||||
}
|
||||
// decryption
|
||||
else {
|
||||
emit qmlOpenPopup();
|
||||
emit wrkDecryptMessage(key.toUtf8(), message.toUtf8());
|
||||
emit wrkDecryptMessage(key, message);
|
||||
}
|
||||
}
|
||||
|
||||
void AppCore::printMessage()
|
||||
{
|
||||
qDebug() << "print message: " << secWorker.message.toHex();
|
||||
emit qmlShowMessage(secWorker.message.toHex());
|
||||
emit qmlClosePopup();
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ signals:
|
||||
void qmlShowKeys(QByteArray pubKey, QByteArray privKey); // to qml
|
||||
|
||||
// encryption and decryption
|
||||
void wrkEncryptMessage(QByteArray pubKey, QByteArray message);
|
||||
void wrkDecryptMessage(QByteArray pubKey, QByteArray message);
|
||||
void wrkEncryptMessage(QString pubKey, QString message);
|
||||
void wrkDecryptMessage(QString pubKey, QString message);
|
||||
void qmlShowMessage(QByteArray message);
|
||||
|
||||
// digital signature
|
||||
|
BIN
Qt-Secret-GUI/images/clear.png
Normal file
BIN
Qt-Secret-GUI/images/clear.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
@ -10,7 +10,7 @@ import "modules/"
|
||||
Window {
|
||||
id: window
|
||||
visible: true
|
||||
width: 640
|
||||
width: 860
|
||||
height: 480
|
||||
title: qsTr("Qt-Secret-GUI")
|
||||
|
||||
|
@ -2,9 +2,12 @@ import QtQuick 2.0
|
||||
import QtQuick.Controls 2.12
|
||||
|
||||
Button {
|
||||
id: privateKeyCpyBtn
|
||||
|
||||
id: btn
|
||||
|
||||
property string source: "../images/cpy.png"
|
||||
implicitWidth: 46
|
||||
implicitHeight: 46
|
||||
|
||||
icon.source: "../images/cpy.png"
|
||||
icon.source: btn.source
|
||||
}
|
@ -4,10 +4,12 @@ import QtQuick.Layouts 1.12
|
||||
|
||||
RowLayout {
|
||||
|
||||
id: encryptDecryptMenu
|
||||
id: doubleStateMenu
|
||||
|
||||
property double verticalSize: 0.1
|
||||
property bool encryptState: true
|
||||
property string firstStateName
|
||||
property string secondStateName
|
||||
property bool state: true
|
||||
|
||||
signal changeState()
|
||||
signal getEncrypDecrypt()
|
||||
@ -18,25 +20,25 @@ RowLayout {
|
||||
Layout.maximumHeight: parentItem.height * verticalSize
|
||||
|
||||
RadioButton {
|
||||
text: qsTr("Encryption")
|
||||
text: firstStateName
|
||||
checked: true
|
||||
onToggled: {
|
||||
encryptState = true
|
||||
doubleStateMenu.state = true
|
||||
changeState()
|
||||
}
|
||||
}
|
||||
|
||||
RadioButton {
|
||||
text: qsTr("Decryption")
|
||||
text: secondStateName
|
||||
onToggled: {
|
||||
encryptState = false
|
||||
doubleStateMenu.state = false
|
||||
changeState()
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: processButton
|
||||
text: (encryptDecryptMenu.encryptState ? qsTr("Encrypt") : qsTr("Decrypt"))
|
||||
text: doubleStateMenu.state ? firstStateName : secondStateName
|
||||
onClicked: getEncrypDecrypt()
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ RowLayout {
|
||||
property string labelText
|
||||
property string textAreaText: labledText.textAreaText
|
||||
property double verticalSize: 0.2
|
||||
property string buttonImageSource
|
||||
|
||||
signal buttonClicked()
|
||||
|
||||
@ -26,7 +27,8 @@ RowLayout {
|
||||
verticalSize: rowElement.verticalSize
|
||||
}
|
||||
|
||||
CopyButton {
|
||||
ActionButton {
|
||||
onClicked: rowElement.buttonClicked()
|
||||
source: rowElement.buttonImageSource
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,12 @@
|
||||
<file>main.qml</file>
|
||||
<file>qtquickcontrols2.conf</file>
|
||||
<file>images/cpy.png</file>
|
||||
<file>modules/CopyButton.qml</file>
|
||||
<file>modules/RowElement.qml</file>
|
||||
<file>modules/LoadPopup.qml</file>
|
||||
<file>modules/RsaGenModule.qml</file>
|
||||
<file>modules/LabledText.qml</file>
|
||||
<file>modules/EncryptDecryptMenu.qml</file>
|
||||
<file>modules/ActionButton.qml</file>
|
||||
<file>images/clear.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -9,15 +9,14 @@ void SecretWorker::generateKeys(int rsa)
|
||||
emit showKeysOnQml();
|
||||
}
|
||||
|
||||
void SecretWorker::encryptMessage(QByteArray pubKey, QByteArray message)
|
||||
void SecretWorker::encryptMessage(QString encPubKey, QString inputText)
|
||||
{
|
||||
qDebug() << "input message: " << message;
|
||||
QRSAEncryption::encodeS(message, pubKey);
|
||||
message = QRSAEncryption::encodeS(inputText.toUtf8(), encPubKey.toUtf8(), QRSAEncryption::Rsa(encPubKey.length() * 4));
|
||||
emit showMessageOnQml();
|
||||
}
|
||||
|
||||
void SecretWorker::decryptMessage(QByteArray privKey, QByteArray message)
|
||||
void SecretWorker::decryptMessage(QString decPrivKey, QString inputMessage)
|
||||
{
|
||||
QRSAEncryption::decodeS(message, privKey);
|
||||
message = QRSAEncryption::decodeS(inputMessage.toUtf8(), decPrivKey.toUtf8(), QRSAEncryption::Rsa(decPrivKey.length() * 4));
|
||||
emit showMessageOnQml();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define SECRETWORKER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <qrsaencryption.h>
|
||||
|
||||
class SecretWorker : public QObject
|
||||
@ -17,8 +18,8 @@ public:
|
||||
|
||||
public slots:
|
||||
void generateKeys(int rsa);
|
||||
void encryptMessage(QByteArray pubKey, QByteArray message);
|
||||
void decryptMessage(QByteArray pubKey, QByteArray message);
|
||||
void encryptMessage(QString encPubKey, QString inputText);
|
||||
void decryptMessage(QString decPrivKey, QString inputMessage);
|
||||
|
||||
signals:
|
||||
void showKeysOnQml();
|
||||
|
@ -167,7 +167,6 @@ unsigned int QRSAEncryption::getKeyBytesSize(QRSAEncryption::Rsa rsa) {
|
||||
// --- static methods ---
|
||||
bool QRSAEncryption::generatePairKeyS(QByteArray &pubKey, QByteArray &privKey,
|
||||
QRSAEncryption::Rsa rsa) {
|
||||
|
||||
return QRSAEncryption(rsa).generatePairKey(pubKey, privKey);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user