本文整理汇总了C++中CSecret类的典型用法代码示例。如果您正苦于以下问题:C++ CSecret类的具体用法?C++ CSecret怎么用?C++ CSecret使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CSecret类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LOCK
bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
{
{
LOCK(cs_KeyStore);
if (!SetCrypted())
return false;
CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
for (; mi != mapCryptedKeys.end(); ++mi)
{
const CPubKey &vchPubKey = (*mi).second.first;
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
CSecret vchSecret;
if(!DecryptSecret(vMasterKeyIn, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))
return false;
if (vchSecret.size() != 32)
return false;
CKey key;
key.SetPubKey(vchPubKey);
key.SetSecret(vchSecret);
if (key.GetPubKey() == vchPubKey)
break;
return false;
}
vMasterKey = vMasterKeyIn;
}
NotifyStatusChanged(this);
return true;
}
示例2: LOCK
bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const
{
{
LOCK(cs_KeyStore);
if (!IsCrypted())
return CBasicKeyStore::GetKey(address, keyOut);
CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
if (mi != mapCryptedKeys.end())
{
const CPubKey &vchPubKey = (*mi).second.first;
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
//CKeyingMaterial vchSecret;
CSecret vchSecret;
if (!DecryptSecret(vMasterKey, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))
return false;
if (vchSecret.size() != 32)
return false;
//keyOut.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed());
keyOut.SetPubKey(vchPubKey);
keyOut.SetSecret(vchSecret);
return true;
}
}
return false;
}
示例3: SetSecret
void CBitcoinSecret::SetSecret(const CSecret& vchSecret, bool fCompressed)
{
assert(vchSecret.size() == 32);
SetData(Params().Base58Prefix(CChainParams::SECRET_KEY), &vchSecret[0], vchSecret.size());
if (fCompressed)
vchData.push_back(1);
}
示例4: GetSecret
CSecret CBitcoinSecret::GetSecret(bool &fCompressedOut)
{
CSecret vchSecret;
vchSecret.resize(32);
memcpy(&vchSecret[0], &vchData[0], 32);
fCompressedOut = vchData.size() == 33;
return vchSecret;
}
示例5: GetSecret
CSecret CKey::GetSecret(bool &fCompressed) const
{
CSecret vchRet;
vchRet.resize(32);
const BIGNUM *bn = EC_KEY_get0_private_key(pkey);
int nBytes = BN_num_bytes(bn);
if (bn == NULL)
throw key_error("CKey::GetSecret() : EC_KEY_get0_private_key failed");
int n=BN_bn2bin(bn,&vchRet[32 - nBytes]);
if (n != nBytes)
throw key_error("CKey::GetSecret(): BN_bn2bin failed");
fCompressed = fCompressedPubKey;
return vchRet;
}
示例6: SetSecret
void CBitcoinSecret::SetSecret(const CSecret& vchSecret, bool fCompressed)
{
assert(vchSecret.size() == 32);
SetData(128 + (fTestNet ? CBitcoinAddress::PUBKEY_ADDRESS_TEST : CBitcoinAddress::PUBKEY_ADDRESS), &vchSecret[0], vchSecret.size());
if (fCompressed)
vchData.push_back(1);
}
示例7: SetSecret
bool CKey::SetSecret(const CSecret& vchSecret, bool fCompressed)
{
if (vchSecret.size() != SCHNORR_SECRET_KEY_SIZE)
return false;
secretKey.Decode(&vchSecret[0], SCHNORR_SECRET_KEY_SIZE);
// generate a new public key
GeneratePublicKey();
fSet = true;
if (fCompressed || fCompressedPubKey)
SetCompressedPubKey();
return true;
}
示例8: dumpKeyInfo
void dumpKeyInfo(uint256 privkey)
{
CSecret secret;
secret.resize(32);
memcpy(&secret[0], &privkey, 32);
vector<unsigned char> sec;
sec.resize(32);
memcpy(&sec[0], &secret[0], 32);
printf(" * secret (hex): %s\n", HexStr(sec).c_str());
for (int nCompressed=0; nCompressed<2; nCompressed++)
{
bool fCompressed = nCompressed == 1;
printf(" * %s:\n", fCompressed ? "compressed" : "uncompressed");
CCosmoscoinSecret bsecret;
bsecret.SetSecret(secret, fCompressed);
printf(" * secret (base58): %s\n", bsecret.ToString().c_str());
CKey key;
key.SetSecret(secret, fCompressed);
vector<unsigned char> vchPubKey = key.GetPubKey();
printf(" * pubkey (hex): %s\n", HexStr(vchPubKey).c_str());
printf(" * address (base58): %s\n", CCosmoscoinAddress(vchPubKey).ToString().c_str());
}
}
示例9: SetSecret
bool CKey::SetSecret(const CSecret &vchSecret, bool fCompressed)
{
EC_KEY_free(pkey);
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
if (pkey == NULL)
throw key_error("CKey::SetSecret() : EC_KEY_new_by_curve_name failed");
if (vchSecret.size() != 32)
throw key_error("CKey::SetSecret() : secret must be 32 bytes");
BIGNUM *bn = BN_bin2bn(&vchSecret[0], 32, BN_new());
if (bn == NULL)
throw key_error("CKey::SetSecret() : BN_bin2bn failed");
if (!EC_KEY_regenerate_key(pkey, bn)) {
BN_clear_free(bn);
throw key_error("CKey::SetSecret() : EC_KEY_regenerate_key failed");
}
BN_clear_free(bn);
fSet = true;
if (fCompressed || fCompressedPubKey)
SetCompressedPubKey();
return true;
}
示例10: main
int main(int argc, char* argv[])
{
if (argc != 7){
printf("Hashchecker needs to know the cryptographic details of your wallet!\nUsage: hashchecker pw_to_permute iterations salt crypted_key public_key crypted_secret\n");
return 1;
}
CCrypter crypter;
CKeyingMaterial vMasterKey;
// Try any password as input
SecureString attempt = argv[1];
const unsigned int nDeriveIterations = atoi(argv[2]);//29731;
const vector<unsigned char> chSalt = Convert(argv[3]);//"b29a2e128e8e0a2f");//argv[1];
const vector<unsigned char> vchCryptedKey = Convert(argv[4]);//"982a07407ccb8d70514e7b7ccae4b53d68318ec41fd2bf99bf9dbcafd2f150a92c6eb8f9ea743b782fc5b85403421c1d");//argv[2];
const vector<unsigned char> vchPubKey = Convert(argv[5]);//"03fefd771544971f3ab95b041bbce02cc799a335d0d12c3bcd46c7c61a4e3ba897");
const vector<unsigned char> vchCryptedSecret = Convert(argv[6]);//"17169083a74b07ff3497027af7423b9aec1593c90f15a57f52c368593947c85e37b03430840ad48ef409e97ba5a4cdeb");
double count = Factorial(attempt.size());
bool found = false;
for (int i = 0; i <= count; i++)
{
if (i > 0) {//test the word as typed in on first iteration
permutation(i-1, attempt);
}
const SecureString strWalletPassphrase = attempt;
cout << i << "-" << strWalletPassphrase <<"\n";
if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, chSalt, nDeriveIterations, 0))
{
cout << i << " " << strWalletPassphrase <<"\n";
continue;
}
if (!crypter.Decrypt(vchCryptedKey, vMasterKey))
{
cout << i << " " << strWalletPassphrase <<"\n";
continue;
}
CSecret vchSecret;
if(!DecryptSecret(vMasterKey, vchCryptedSecret, Hash(vchPubKey.begin(), vchPubKey.end()), vchSecret))
{
cout << "** didn't decrypt **" <<"\n";
continue;
}
if (vchSecret.size() != 32)
{
cout << "** wrong size secret **" <<"\n";
continue;
}
CKey key;
key.SetPubKey(vchPubKey);
key.SetSecret(vchSecret);
if (key.GetPubKey() == vchPubKey)
{
cout<<"Found one: "<<strWalletPassphrase<<"\n";
found = true;
break;
}
// else
// cout << "** didn't get the pubkey back **\n";
}
if (found)
cout << "Found it! Congratulations\n";
return 0;
}
示例11: LogPrintf
bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
{
if (fDebug)
LogPrintf("CCryptoKeyStore::Unlock()\n");
{
LOCK(cs_KeyStore);
if (!SetCrypted())
return false;
int nUnlocked = 0;
CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
for (; mi != mapCryptedKeys.end(); ++mi)
{
const CPubKey &vchPubKey = (*mi).second.first;
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
CSecret vchSecret;
if (vchCryptedSecret.size() < 1) // key was recieved from stealth/anon txn with wallet locked, will be expanded after this
{
if (fDebug)
LogPrintf("Skipping unexpanded key %s.\n", vchPubKey.GetHash().ToString().c_str());
continue;
};
if (!DecryptSecret(vMasterKeyIn, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))
{
LogPrintf("DecryptSecret() failed.\n");
return false;
};
if (vchSecret.size() != 32)
return false;
CKey key;
key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed());
if (key.GetPubKey() != vchPubKey)
{
LogPrintf("Unlock failed: PubKey mismatch %s.\n", vchPubKey.GetHash().ToString().c_str());
return false;
};
nUnlocked++;
break;
};
if (nUnlocked < 1) // at least 1 key must pass the test
{
if (mapCryptedKeys.size() > 0)
{
LogPrintf("Unlock failed: No keys unlocked.\n");
return false;
};
};
vMasterKey = vMasterKeyIn;
}
NotifyStatusChanged(this);
return true;
}