X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Frpccrypt.cpp;h=69e14c09c106520fcaee3d05f3d7dcb990dc0e5b;hb=873e98f49efa6a14f2c01ffa7ce3d8167450ff3b;hp=056917636608c91382e1826b959929d0f0dffad2;hpb=b17ed6bfad24c6e140030f0bea4686c0d4c0fbaa;p=novacoin.git diff --git a/src/rpccrypt.cpp b/src/rpccrypt.cpp index 0569176..69e14c0 100644 --- a/src/rpccrypt.cpp +++ b/src/rpccrypt.cpp @@ -4,11 +4,8 @@ // 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; @@ -50,3 +47,44 @@ Value decryptdata(const Array& params, bool fHelp) return HexStr(vchDecrypted); } + +Value encryptmessage(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 2) + throw runtime_error( + "encryptmessage \n" + "Encrypt message with provided public key.\n"); + + CPubKey pubKey(ParseHex(params[0].get_str())); + + vector vchEncrypted; + string strData = params[1].get_str(); + pubKey.EncryptData(vector(strData.begin(), strData.end()), vchEncrypted); + + return EncodeBase58Check(vchEncrypted); +} + +Value decryptmessage(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 2) + throw runtime_error( + "decryptmessage \n" + "Decrypt message string.\n"); + + EnsureWalletIsUnlocked(); + CBitcoinAddress addr(params[0].get_str()); + + CKeyID keyID; + addr.GetKeyID(keyID); + + CKey key; + pwalletMain->GetKey(keyID, key); + + vector vchEncrypted; + if (!DecodeBase58Check(params[1].get_str(), vchEncrypted)) + throw runtime_error("Incorrect string"); + vector vchDecrypted; + key.DecryptData(vchEncrypted, vchDecrypted); + + return std::string((const char*)&vchDecrypted[0], vchDecrypted.size()); +}