History

use OpenSSL to create signed wallet transaction using hard-code key

Stephen Birarda committed 12 years ago

Commit cb9a2c61 parent 74a107f4 files · +51 −12Browse files

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

Unified · Split

interface/src/SignedWalletTransaction.cpp+32−4
@@ -13,6 +13,12 @@ · 12 unmodified lines
1313 #include <QtCore/QDebug>
1414 #include <QtCore/QFile>
1515
16+#include <openssl/bio.h>
17+#include <openssl/rsa.h>
18+#include <openssl/pem.h>
19+
20+#include <AccountManager.h>
21+
1622 #include "SignedWalletTransaction.h"
1723
1824 SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount,
@@ -35,9 +41,7 @@ QByteArray SignedWalletTransaction::hexMessage() { · 16 unmodified lines
3541 messageBinary.append(reinterpret_cast<const char*>(&_messageTimestamp), sizeof(_messageTimestamp));
3642 messageBinary.append(reinterpret_cast<const char*>(&_expiryDelta), sizeof(_expiryDelta));
3743
38− QUuid sourceUUID = QUuid::createUuid();
39− qDebug() << "The faked source UUID is" << sourceUUID;
40− messageBinary.append(sourceUUID.toRfc4122());
44+ messageBinary.append(AccountManager::getInstance().getAccountInfo().getWalletID().toRfc4122());
4145
4246 messageBinary.append(_destinationUUID.toRfc4122());
4347
@@ -47,5 +51,29 @@ QByteArray SignedWalletTransaction::hexMessage() { · 3 unmodified lines
4751 }
4852
4953 QByteArray SignedWalletTransaction::messageDigest() {
50− return QCryptographicHash::hash(hexMessage(), QCryptographicHash::Sha256);
54+ return QCryptographicHash::hash(hexMessage(), QCryptographicHash::Sha256).toHex();
55+}
56+
57+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();
62+
63+ BIO* privateKeyBIO = NULL;
64+ RSA* rsaPrivateKey = NULL;
65+
66+ privateKeyBIO = BIO_new_mem_buf(privateKeyData.data(), privateKeyData.size());
67+ PEM_read_bio_RSAPrivateKey(privateKeyBIO, &rsaPrivateKey, NULL, NULL);
68+
69+ QByteArray digestToEncrypt = messageDigest();
70+ qDebug() << "encrypting the following digest" << digestToEncrypt;
71+ QByteArray encryptedDigest(RSA_size(rsaPrivateKey), 0);
72+
73+ int encryptReturn = RSA_private_encrypt(digestToEncrypt.size(),
74+ reinterpret_cast<const unsigned char*>(digestToEncrypt.constData()),
75+ reinterpret_cast<unsigned char*>(encryptedDigest.data()),
76+ rsaPrivateKey, RSA_PKCS1_PADDING);
77+
78+ return encryptedDigest;
5179 }