本文整理汇总了C++中KeyPair类的典型用法代码示例。如果您正苦于以下问题:C++ KeyPair类的具体用法?C++ KeyPair怎么用?C++ KeyPair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KeyPair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _password
KeyPair KeyManager::presaleSecret(std::string const& _json, function<string(bool)> const& _password)
{
js::mValue val;
json_spirit::read_string(_json, val);
auto obj = val.get_obj();
string p = _password(true);
if (obj["encseed"].type() == js::str_type)
{
auto encseed = fromHex(obj["encseed"].get_str());
KeyPair k;
for (bool gotit = false; !gotit;)
{
gotit = true;
k = KeyPair::fromEncryptedSeed(&encseed, p);
if (obj["ethaddr"].type() == js::str_type)
{
Address a(obj["ethaddr"].get_str());
Address b = k.address();
if (a != b)
{
if ((p = _password(false)).empty())
BOOST_THROW_EXCEPTION(PasswordUnknown());
else
gotit = false;
}
}
}
return k;
}
else
BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("encseed type is not js::str_type"));
}
示例2: l
void MixClient::resetState(std::map<Secret, u256> _accounts, Secret _miner)
{
WriteGuard l(x_state);
Guard fl(x_filtersWatches);
m_filters.clear();
m_watches.clear();
m_stateDB = OverlayDB();
SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB);
accountState.init();
m_userAccounts.clear();
std::map<Address, Account> genesisState;
for (auto account: _accounts)
{
KeyPair a = KeyPair(account.first);
m_userAccounts.push_back(a);
genesisState.insert(std::make_pair(a.address(), Account(account.second, Account::NormalCreation)));
}
dev::eth::commit(genesisState, static_cast<MemoryDB&>(m_stateDB), accountState);
h256 stateRoot = accountState.root();
m_bc.reset();
m_bc.reset(new MixBlockChain(m_dbPath, stateRoot));
m_state = eth::State(m_stateDB, BaseState::PreExisting, KeyPair(_miner).address());
m_state.sync(bc());
m_startState = m_state;
WriteGuard lx(x_executions);
m_executions.clear();
}
示例3: shh_newIdentity
std::string WebThreeStubServerBase::shh_newIdentity()
{
// cnote << this << m_ids;
KeyPair kp = KeyPair::create();
m_ids[kp.pub()] = kp.secret();
return toJS(kp.pub());
}
示例4: Encrypt
bool KeyPair::Encrypt(Ciphertext& out, Digest key) {
KeyPair temp;
temp.Keygen();
memcpy(out, &temp.publicKey[1], sizeof(out));
if (!ecdh_shared_secret(publicKey, temp.privateKey, key.Byte)) return false;
blake2b(key, sizeof(key), 0, 0, key, sizeof(key));
return true;
}
示例5: connect
void NewAccount::create()
{
QDialog d;
Ui::NewAccount u;
u.setupUi(&d);
u.keysPath->setText(QString::fromStdString(getDataDir("web3/keys")));
auto updateStatus = [&]()
{
bool useMaster = u.useMaster->isChecked();
u.password->setEnabled(!useMaster);
u.confirm->setEnabled(!useMaster);
u.hint->setEnabled(!useMaster);
u.status->setText("");
bool ok = (useMaster || (!u.password->text().isEmpty() && u.password->text() == u.confirm->text()));
if (!ok)
u.status->setText("Passphrases must match");
if (u.keyName->text().isEmpty())
{
ok = false;
u.status->setText("Name must not be empty");
}
u.create->setEnabled(ok);
};
connect(u.useMaster, &QCheckBox::toggled, [&]() { updateStatus(); });
connect(u.useOwn, &QCheckBox::toggled, [&]() { updateStatus(); });
connect(u.password, &QLineEdit::textChanged, [&]() { updateStatus(); });
connect(u.keyName, &QLineEdit::textChanged, [&]() { updateStatus(); });
connect(u.confirm, &QLineEdit::textChanged, [&]() { updateStatus(); });
updateStatus();
if (d.exec() == QDialog::Accepted)
{
KeyManager::NewKeyType v = (KeyManager::NewKeyType)u.keyType->currentIndex();
KeyPair p = KeyManager::newKeyPair(v);
QString s = u.keyName->text();
if (u.useMaster->isChecked())
aleth()->keyManager().import(p.secret(), s.toStdString());
else
{
std::string hint = u.hint->toPlainText().toStdString();
std::string password = u.password->text().toStdString();
aleth()->keyManager().import(p.secret(), s.toStdString(), password, hint);
}
aleth()->noteKeysChanged();
}
}
示例6: endecryptTest
void endecryptTest()
{
const unsigned int bitLength = 128;
KeyPair pair = RSA::makeKeyPair(bitLength);
PublicKey pubKey = pair.getPublicKey();
PrivateKey privKey = pair.getPrivateKey();
RSA cipher(pubKey, privKey);
MPInteger plaintext("12fbff45836b");
MPInteger ciphertext = cipher.encrypt(plaintext);
MPInteger decrypttext = cipher.decrypt(ciphertext);
CPPUNIT_ASSERT(plaintext == decrypttext);
}
示例7: NodeSocket
NodeTable::NodeTable(ba::io_service& _io, KeyPair _alias, uint16_t _udp):
m_node(Node(_alias.pub(), bi::udp::endpoint())),
m_secret(_alias.sec()),
m_io(_io),
m_socket(new NodeSocket(m_io, *this, _udp)),
m_socketPointer(m_socket.get()),
m_bucketRefreshTimer(m_io),
m_evictionCheckTimer(m_io)
{
for (unsigned i = 0; i < s_bins; i++)
{
m_state[i].distance = i;
m_state[i].modified = chrono::steady_clock::now() - chrono::seconds(1);
}
m_socketPointer->connect();
doRefreshBuckets(boost::system::error_code());
}
示例8: stateTest
int stateTest()
{
KeyPair me = sha3("Gav Wood");
KeyPair myMiner = sha3("Gav's Miner");
// KeyPair you = sha3("123");
Defaults::setDBPath("/tmp");
Overlay stateDB = State::openDB();
BlockChain bc;
State s(myMiner.address(), stateDB);
cout << bc;
// Sync up - this won't do much until we use the last state.
s.sync(bc);
cout << s;
// Mine to get some ether!
s.commitToMine(bc);
while (s.mine(100).completed) {}
bc.attemptImport(s.blockData(), stateDB);
cout << bc;
s.sync(bc);
cout << s;
// Inject a transaction to transfer funds from miner to me.
bytes tx;
{
Transaction t;
t.nonce = s.transactionsFrom(myMiner.address());
t.value = 1000; // 1e3 wei.
t.receiveAddress = me.address();
t.sign(myMiner.secret());
assert(t.sender() == myMiner.address());
tx = t.rlp();
}
s.execute(tx);
cout << s;
// Mine to get some ether and set in stone.
s.commitToMine(bc);
while (s.mine(100).completed) {}
bc.attemptImport(s.blockData(), stateDB);
cout << bc;
s.sync(bc);
cout << s;
return 0;
}
示例9: main
int main()
{
KeyPair u = KeyPair::create();
KeyPair cb = KeyPair::create();
OverlayDB db;
State s(cb.address(), db, BaseState::Empty);
cnote << s.rootHash();
s.addBalance(u.address(), 1 * ether);
Address c = s.newContract(1000 * ether, compileLLL("(suicide (caller))"));
s.commit();
State before = s;
cnote << "State before transaction: " << before;
Transaction t(0, 10000, 10000, c, bytes(), 0, u.secret());
cnote << "Transaction: " << t;
cnote << s.balance(c);
s.execute(LastHashes(), t.rlp());
cnote << "State after transaction: " << s;
cnote << before.diff(s);
}
示例10: NodeSocket
NodeTable::NodeTable(ba::io_service& _io, KeyPair const& _alias, NodeIPEndpoint const& _endpoint, bool _enabled):
m_node(Node(_alias.pub(), _endpoint)),
m_secret(_alias.sec()),
m_socket(new NodeSocket(_io, *this, (bi::udp::endpoint)m_node.endpoint)),
m_socketPointer(m_socket.get()),
m_timers(_io)
{
for (unsigned i = 0; i < s_bins; i++)
m_state[i].distance = i;
if (!_enabled)
return;
try
{
m_socketPointer->connect();
doDiscovery();
}
catch (std::exception const& _e)
{
clog(NetWarn) << "Exception connecting NodeTable socket: " << _e.what();
clog(NetWarn) << "Discovery disabled.";
}
}
示例11: keyCreateTest
void keyCreateTest()
{
const unsigned int bitLength = 256;
KeyPair pair = RSA::makeKeyPair(bitLength);
CPPUNIT_ASSERT(
pair.getPublicKey().getEncryptExponent().getBitLength() == 17);
CPPUNIT_ASSERT(
pair.getPublicKey().getModulus() ==
pair.getPrivateKey().getModulus());
PublicKey pubKey = pair.getPublicKey();
PrivateKey privKey = pair.getPrivateKey();
}
示例12: shh_newIdentity
string WebThreeStubServerBase::shh_newIdentity()
{
KeyPair kp = KeyPair::create();
m_shhIds[kp.pub()] = kp.secret();
return toJS(kp.pub());
}
示例13: execute
bool AccountManager::execute(int argc, char** argv)
{
if (string(argv[1]) == "wallet")
{
if (3 < argc && string(argv[2]) == "import")
{
if (!openWallet())
return false;
string file = argv[3];
string name = "presale wallet";
string pw;
KeyPair k;
try
{
k = m_keyManager->presaleSecret(
contentsString(file),
[&](bool){ return (pw = getPassword("Enter the passphrase for the presale key: "));}
);
}
catch (Exception const& _e)
{
if (auto err = boost::get_error_info<errinfo_comment>(_e))
cout << " Decryption failed: " << *err << endl;
else
cout << " Decryption failed: Unknown reason." << endl;
return false;
}
m_keyManager->import(k.secret(), name, pw, "Same passphrase as used for presale key");
cout << " Address: {" << k.address().hex() << "}" << endl;
}
else
streamWalletHelp(cout);
return true;
}
else if (string(argv[1]) == "account")
{
if (argc < 3 || string(argv[2]) == "list")
{
openWallet();
if (m_keyManager->store().keys().empty())
cout << "No keys found." << endl;
else
{
vector<u128> bare;
AddressHash got;
int k = 0;
for (auto const& u: m_keyManager->store().keys())
{
if (Address a = m_keyManager->address(u))
{
got.insert(a);
cout << "Account #" << k << ": {" << a.hex() << "}" << endl;
k++;
}
else
bare.push_back(u);
}
for (auto const& a: m_keyManager->accounts())
if (!got.count(a))
{
cout << "Account #" << k << ": {" << a.hex() << "}" << " (Brain)" << endl;
k++;
}
for (auto const& u: bare)
{
cout << "Account #" << k << ": " << toUUID(u) << " (Bare)" << endl;
k++;
}
}
}
else if (2 < argc && string(argv[2]) == "new")
{
openWallet();
string name;
string lock;
string lockHint;
lock = createPassword("Enter a passphrase with which to secure this account:");
auto k = makeKey();
h128 u = m_keyManager->import(k.secret(), name, lock, lockHint);
cout << "Created key " << toUUID(u) << endl;
cout << " ICAP: " << ICAP(k.address()).encoded() << endl;
cout << " Address: {" << k.address().hex() << "}" << endl;
}
else if (3 < argc && string(argv[2]) == "import")
{
openWallet();
h128 u = m_keyManager->store().importKey(argv[3]);
if (!u)
{
cerr << "Error: reading key file failed" << endl;
return false;
}
string pw;
bytesSec s = m_keyManager->store().secret(u, [&](){ return (pw = getPassword("Enter the passphrase for the key: ")); });
if (s.empty())
{
cerr << "Error: couldn't decode key or invalid secret size." << endl;
return false;
}
else
//.........这里部分代码省略.........
示例14: main
int main(int argc, char** argv)
{
unsigned short listenPort = 30303;
string remoteHost;
unsigned short remotePort = 30303;
string dbPath;
bool mining = false;
unsigned peers = 5;
#if ETH_JSONRPC
int jsonrpc = 8080;
#endif
string publicIP;
bool upnp = true;
string clientName;
// Init defaults
Defaults::get();
// Our address.
KeyPair us = KeyPair::create();
Address coinbase = us.address();
string configFile = getDataDir() + "/config.rlp";
bytes b = contents(configFile);
if (b.size())
{
RLP config(b);
us = KeyPair(config[0].toHash<Secret>());
coinbase = config[1].toHash<Address>();
}
else
{
RLPStream config(2);
config << us.secret() << coinbase;
writeFile(configFile, config.out());
}
for (int i = 1; i < argc; ++i)
{
string arg = argv[i];
if ((arg == "-l" || arg == "--listen" || arg == "--listen-port") && i + 1 < argc)
listenPort = (short)atoi(argv[++i]);
else if ((arg == "-u" || arg == "--public-ip" || arg == "--public") && i + 1 < argc)
publicIP = argv[++i];
else if ((arg == "-r" || arg == "--remote") && i + 1 < argc)
remoteHost = argv[++i];
else if ((arg == "-p" || arg == "--port") && i + 1 < argc)
remotePort = (short)atoi(argv[++i]);
else if ((arg == "-n" || arg == "--upnp") && i + 1 < argc)
{
string m = argv[++i];
if (isTrue(m))
upnp = true;
else if (isFalse(m))
upnp = false;
else
{
cerr << "Invalid UPnP option: " << m << endl;
return -1;
}
}
else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc)
clientName = argv[++i];
else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc)
coinbase = h160(fromHex(argv[++i]));
else if ((arg == "-s" || arg == "--secret") && i + 1 < argc)
us = KeyPair(h256(fromHex(argv[++i])));
else if ((arg == "-d" || arg == "--path" || arg == "--db-path") && i + 1 < argc)
dbPath = argv[++i];
else if ((arg == "-m" || arg == "--mining") && i + 1 < argc)
{
string m = argv[++i];
if (isTrue(m))
mining = true;
else if (isFalse(m))
mining = false;
else
{
cerr << "Unknown mining option: " << m << endl;
}
}
#if ETH_JSONRPC
else if ((arg == "-j" || arg == "--json-rpc"))
jsonrpc = jsonrpc ? jsonrpc : 8080;
else if (arg == "--json-rpc-port" && i + 1 < argc)
jsonrpc = atoi(argv[++i]);
#endif
else if ((arg == "-v" || arg == "--verbosity") && i + 1 < argc)
g_logVerbosity = atoi(argv[++i]);
else if ((arg == "-x" || arg == "--peers") && i + 1 < argc)
peers = atoi(argv[++i]);
else if (arg == "-h" || arg == "--help")
help();
else if (arg == "-V" || arg == "--version")
version();
else
remoteHost = argv[i];
}
if (!clientName.empty())
//.........这里部分代码省略.........
示例15: on_create_clicked
void Main::on_create_clicked()
{
KeyPair p = KeyPair::create();
QString s = QString::fromStdString("The new secret key is:\n" + asHex(p.secret().asArray()) + "\n\nAddress:\n" + asHex(p.address().asArray()));
QMessageBox::information(this, "Create Key", s, QMessageBox::Ok);
}