Examples and missed file.
[novacoin.git] / src / rpccrypt.cpp
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6 #include "wallet.h"
7 #include "walletdb.h"
8 #include "bitcoinrpc.h"
9 #include "init.h"
10 #include "util.h"
11 #include "ntp.h"
12 #include "base58.h"
13
14 using namespace json_spirit;
15 using namespace std;
16
17 Value encryptdata(const Array& params, bool fHelp)
18 {
19     if (fHelp || params.size() != 2)
20         throw runtime_error(
21             "encryptdata <public key> <hex data>\n"
22             "Encrypt octet stream with provided public key..\n");
23
24     CPubKey pubKey(ParseHex(params[0].get_str()));
25
26     vector<unsigned char> vchEncrypted;
27     pubKey.EncryptData(ParseHex(params[1].get_str()), vchEncrypted);
28
29     return HexStr(vchEncrypted);
30 }
31
32 Value decryptdata(const Array& params, bool fHelp)
33 {
34     if (fHelp || params.size() != 2)
35         throw runtime_error(
36             "decryptdata <novacoin address> <encrypted stream>\n"
37             "Decrypt octet stream.\n");
38
39     EnsureWalletIsUnlocked();
40     CBitcoinAddress addr(params[0].get_str());
41
42     CKeyID keyID;
43     addr.GetKeyID(keyID);
44
45     CKey key;
46     pwalletMain->GetKey(keyID, key);
47
48     vector<unsigned char> vchDecrypted;
49     key.DecryptData(ParseHex(params[1].get_str()), vchDecrypted);
50
51     return HexStr(vchDecrypted);
52 }