History

add dialog to Menu to insert wallet private key

Stephen Birarda committed 12 years ago

Commit 45ae9f61 parent 0c8c4a25 files · +42 −11Browse files

Showing the changes to interface/src/SignedWalletTransaction.cpp (1 of 5 files). Show all

Unified · Split

interface/src/SignedWalletTransaction.cpp+10−7
@@ -19,6 +19,8 @@ · 18 unmodified lines
1919
2020 #include <AccountManager.h>
2121
22+#include "Menu.h"
23+
2224 #include "SignedWalletTransaction.h"
2325
2426 SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount,
@@ -55,19 +57,16 @@ QByteArray SignedWalletTransaction::messageDigest() { · 30 unmodified lines
5557 }
5658
5759 QByteArray SignedWalletTransaction::signedMessageDigest() {
58− // read the private key from file into memory
59− QFile privateKeyFile("/Users/birarda/Desktop/generated-private.pem");
60− privateKeyFile.open(QIODevice::ReadOnly);
61− QByteArray privateKeyData = privateKeyFile.readAll();
60+ // pull the current private key from menu into RSA structure in memory
61+ QByteArray privateKeyByteArray = Menu::getInstance()->getWalletPrivateKey();
6262
6363 BIO* privateKeyBIO = NULL;
6464 RSA* rsaPrivateKey = NULL;
6565
66− privateKeyBIO = BIO_new_mem_buf(privateKeyData.data(), privateKeyData.size());
66+ privateKeyBIO = BIO_new_mem_buf(privateKeyByteArray.data(), privateKeyByteArray.size());
6767 PEM_read_bio_RSAPrivateKey(privateKeyBIO, &rsaPrivateKey, NULL, NULL);
6868
6969 QByteArray digestToEncrypt = messageDigest();
70− qDebug() << "encrypting the following digest" << digestToEncrypt;
7170 QByteArray encryptedDigest(RSA_size(rsaPrivateKey), 0);
7271
7372 int encryptReturn = RSA_private_encrypt(digestToEncrypt.size(),
@@ -75,5 +74,9 @@ QByteArray SignedWalletTransaction::signedMessageDigest() { · 1 unmodified line
7574 reinterpret_cast<unsigned char*>(encryptedDigest.data()),
7675 rsaPrivateKey, RSA_PKCS1_PADDING);
7776
78− return encryptedDigest;
77+ // free the two structures used
78+ BIO_free(privateKeyBIO);
79+ RSA_free(rsaPrivateKey);
80+
81+ return (encryptReturn != -1) ? encryptedDigest : QByteArray();
7982 }