--- /dev/null
+Encryption RPC api allows you to encrypt an arbitrary data bytes with some public key. Only owner of corresponding private key will be able to recover the original data stream.
+
+Example
+
+1. Let's generate new novacoin address first.
+
+> getnewaddress
+4NZFZZS9b8iawVA8sYtHsqNbpq57envuBz
+
+2. Then run validateaddress to dump its public key
+
+> validateaddress 4NZFZZS9b8iawVA8sYtHsqNbpq57envuBz
+{
+"isvalid" : true,
+"address" : "4NZFZZS9b8iawVA8sYtHsqNbpq57envuBz",
+"ismine" : true,
+"watchonly" : false,
+"isscript" : false,
+"pubkey" : "023ca82f71f40d18f5cf6a696367a4172b87d7b3db5f45086bdb4bd4a3e3e9bde9",
+"iscompressed" : true,
+"account" : ""
+}
+
+3. Trying to encrypt hex representation of "Hello world!" string using this public key.
+
+> encryptdata 023ca82f71f40d18f5cf6a696367a4172b87d7b3db5f45086bdb4bd4a3e3e9bde9 48656c6c6f20776f726c6421
+02a2fe5afb10c40fc64552e1b81d8b4e991838d50c6a7129bd9f466eee29a5ab9def7cc5a3b1b526d59d06178fa4471b778e80bf8f72ae34889e58a4568f8ad2a3ecc9004a
+
+4. Now we should be able to decrypt that cryptogram into original byte stream.
+
+> decryptdata 4NZFZZS9b8iawVA8sYtHsqNbpq57envuBz 02a2fe5afb10c40fc64552e1b81d8b4e991838d50c6a7129bd9f466eee29a5ab9def7cc5a3b1b526d59d06178fa4471b778e80bf8f72ae34889e58a4568f8ad2a3ecc9004a
+48656c6c6f20776f726c6421
src/qt/transactionview.cpp \
src/qt/walletmodel.cpp \
src/bitcoinrpc.cpp \
+ src/rpccrypt.cpp \
src/rpcdump.cpp \
src/rpcnet.cpp \
src/rpcmining.cpp \
{ "adjustmalleablepubkey", &adjustmalleablepubkey, false, false},
{ "listmalleableviews", &listmalleableviews, false, false},
{ "dumpmalleablekey", &dumpmalleablekey, false, false},
+ { "encryptdata", &encryptdata, false, false },
+ { "decryptdata", &decryptdata, false, false },
{ "sendalert", &sendalert, false, false},
};
extern json_spirit::Value listmalleableviews(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value dumpmalleablekey(const json_spirit::Array& params, bool fHelp);
+extern json_spirit::Value encryptdata(const json_spirit::Array& params, bool fHelp); // in rpccrypt.cpp
+extern json_spirit::Value decryptdata(const json_spirit::Array& params, bool fHelp);
+
extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value createrawtransaction(const json_spirit::Array& params, bool fHelp);
unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake)
{
if (pindexLast == NULL)
- return bnTargetLimit.GetCompact(); // genesis block
+ return bnProofOfWorkLimit.GetCompact(); // genesis block
CBigNum bnTargetLimit = !fProofOfStake ? bnProofOfWorkLimit : GetProofOfStakeLimit(pindexLast->nHeight, pindexLast->nTime);
obj/stun.o \
obj/protocol.o \
obj/bitcoinrpc.o \
+ obj/rpccrypt.o \
obj/rpcdump.o \
obj/rpcnet.o \
obj/rpcmining.o \
obj/stun.o \
obj/protocol.o \
obj/bitcoinrpc.o \
+ obj/rpccrypt.o \
obj/rpcdump.o \
obj/rpcnet.o \
obj/rpcmining.o \
obj/stun.o \
obj/protocol.o \
obj/bitcoinrpc.o \
+ obj/rpccrypt.o \
obj/rpcdump.o \
obj/rpcnet.o \
obj/rpcmining.o \
obj/stun.o \
obj/protocol.o \
obj/bitcoinrpc.o \
+ obj/rpccrypt.o \
obj/rpcdump.o \
obj/rpcnet.o \
obj/rpcmining.o \
obj/stun.o \
obj/protocol.o \
obj/bitcoinrpc.o \
+ obj/rpccrypt.o \
obj/rpcdump.o \
obj/rpcnet.o \
obj/rpcmining.o \
--- /dev/null
+// Copyright (c) 2010 Satoshi Nakamoto
+// Copyright (c) 2009-2012 The Bitcoin developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include "wallet.h"
+#include "walletdb.h"
+#include "bitcoinrpc.h"
+#include "init.h"
+#include "util.h"
+#include "ntp.h"
+#include "base58.h"
+
+using namespace json_spirit;
+using namespace std;
+
+Value encryptdata(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 2)
+ throw runtime_error(
+ "encryptdata <public key> <hex data>\n"
+ "Encrypt octet stream with provided public key..\n");
+
+ CPubKey pubKey(ParseHex(params[0].get_str()));
+
+ vector<unsigned char> vchEncrypted;
+ pubKey.EncryptData(ParseHex(params[1].get_str()), vchEncrypted);
+
+ return HexStr(vchEncrypted);
+}
+
+Value decryptdata(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 2)
+ throw runtime_error(
+ "decryptdata <novacoin address> <encrypted stream>\n"
+ "Decrypt octet stream.\n");
+
+ EnsureWalletIsUnlocked();
+ CBitcoinAddress addr(params[0].get_str());
+
+ CKeyID keyID;
+ addr.GetKeyID(keyID);
+
+ CKey key;
+ pwalletMain->GetKey(keyID, key);
+
+ vector<unsigned char> vchDecrypted;
+ key.DecryptData(ParseHex(params[1].get_str()), vchDecrypted);
+
+ return HexStr(vchDecrypted);
+}