std::string EncodeSecret(const CKey& key) { assert(key.IsValid()); std::vector<unsigned char> data = Params().Base58Prefix(CChainParams::SECRET_KEY); data.insert(data.end(), key.begin(), key.end()); if (key.IsCompressed()) { data.push_back(1); } std::string ret = EncodeBase58Check(data); memory_cleanse(data.data(), data.size()); return ret; }
bool CCryptoKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey) { { LOCK(cs_KeyStore); if (!IsCrypted()) return CBasicKeyStore::AddKeyPubKey(key, pubkey); if (IsLocked()) return false; std::vector<unsigned char> vchCryptedSecret; CKeyingMaterial vchSecret(key.begin(), key.end()); if (!EncryptSecret(vMasterKey, vchSecret, pubkey.GetHash(), vchCryptedSecret)) return false; // -- NOTE: this is CWallet::AddCryptedKey if (!AddCryptedKey(pubkey, vchCryptedSecret)) return false; } return true; }
bool HaveKey(const CKeyStore& store, const CKey& key) { CKey key2; key2.Set(key.begin(), key.end(), !key.IsCompressed()); return store.HaveKey(key.GetPubKey().GetID()) || store.HaveKey(key2.GetPubKey().GetID()); }