Showing the changes to interface/src/SignedWalletTransaction.cpp (1 of 5 files). Show all
Unified · Split
| @@ -19,6 +19,8 @@ · 18 unmodified lines | |||
| 19 | 19 | ||
| 20 | #include <AccountManager.h> | 20 | #include <AccountManager.h> |
| 21 | 21 | ||
| 22 | #include "Menu.h" | ||
| 23 | |||
| 22 | #include "SignedWalletTransaction.h" | 24 | #include "SignedWalletTransaction.h" |
| 23 | 25 | ||
| 24 | SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount, | 26 | SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount, |
| @@ -55,19 +57,16 @@ QByteArray SignedWalletTransaction::messageDigest() { · 30 unmodified lines | |||
| 55 | } | 57 | } |
| 56 | 58 | ||
| 57 | QByteArray SignedWalletTransaction::signedMessageDigest() { | 59 | QByteArray SignedWalletTransaction::signedMessageDigest() { |
| 58 | // read the private key from file into memory | 60 | // pull the current private key from menu into RSA structure in memory |
| 59 | QFile privateKeyFile("/Users/birarda/Desktop/generated-private.pem"); | 61 | QByteArray privateKeyByteArray = Menu::getInstance()->getWalletPrivateKey(); |
| 60 | privateKeyFile.open(QIODevice::ReadOnly); | ||
| 61 | QByteArray privateKeyData = privateKeyFile.readAll(); | ||
| 62 | 62 | ||
| 63 | BIO* privateKeyBIO = NULL; | 63 | BIO* privateKeyBIO = NULL; |
| 64 | RSA* rsaPrivateKey = NULL; | 64 | RSA* rsaPrivateKey = NULL; |
| 65 | 65 | ||
| 66 | privateKeyBIO = BIO_new_mem_buf(privateKeyData.data(), privateKeyData.size()); | 66 | privateKeyBIO = BIO_new_mem_buf(privateKeyByteArray.data(), privateKeyByteArray.size()); |
| 67 | PEM_read_bio_RSAPrivateKey(privateKeyBIO, &rsaPrivateKey, NULL, NULL); | 67 | PEM_read_bio_RSAPrivateKey(privateKeyBIO, &rsaPrivateKey, NULL, NULL); |
| 68 | 68 | ||
| 69 | QByteArray digestToEncrypt = messageDigest(); | 69 | QByteArray digestToEncrypt = messageDigest(); |
| 70 | qDebug() << "encrypting the following digest" << digestToEncrypt; | ||
| 71 | QByteArray encryptedDigest(RSA_size(rsaPrivateKey), 0); | 70 | QByteArray encryptedDigest(RSA_size(rsaPrivateKey), 0); |
| 72 | 71 | ||
| 73 | int encryptReturn = RSA_private_encrypt(digestToEncrypt.size(), | 72 | int encryptReturn = RSA_private_encrypt(digestToEncrypt.size(), |
| @@ -75,5 +74,9 @@ QByteArray SignedWalletTransaction::signedMessageDigest() { · 1 unmodified line | |||
| 75 | reinterpret_cast<unsigned char*>(encryptedDigest.data()), | 74 | reinterpret_cast<unsigned char*>(encryptedDigest.data()), |
| 76 | rsaPrivateKey, RSA_PKCS1_PADDING); | 75 | rsaPrivateKey, RSA_PKCS1_PADDING); |
| 77 | 76 | ||
| 78 | return encryptedDigest; | 77 | // free the two structures used |
| 78 | BIO_free(privateKeyBIO); | ||
| 79 | RSA_free(rsaPrivateKey); | ||
| 80 | |||
| 81 | return (encryptReturn != -1) ? encryptedDigest : QByteArray(); | ||
| 79 | } | 82 | } |