当前位置: 首页>>代码示例>>C++>>正文


C++ CSecret类代码示例

本文整理汇总了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;
}
开发者ID:ColoradoPay,项目名称:CPAY,代码行数:29,代码来源:keystore.cpp

示例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;
}
开发者ID:TheBitcoin,项目名称:Feathercoin2,代码行数:26,代码来源:crypter.cpp

示例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);
}
开发者ID:TheBitcoin,项目名称:Feathercoin2,代码行数:7,代码来源:base58.cpp

示例4: GetSecret

 CSecret CBitcoinSecret::GetSecret(bool &fCompressedOut)
 {
     CSecret vchSecret;
     vchSecret.resize(32);
     memcpy(&vchSecret[0], &vchData[0], 32);
     fCompressedOut = vchData.size() == 33;
     return vchSecret;
 }
开发者ID:5mil,项目名称:Scryptic,代码行数:8,代码来源:base58.cpp

示例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;
}
开发者ID:uscoin,项目名称:uscoin,代码行数:14,代码来源:key.cpp

示例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);
 }
开发者ID:5mil,项目名称:Scryptic,代码行数:7,代码来源:base58.cpp

示例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;
}
开发者ID:HelixCoin,项目名称:HelixCoin,代码行数:14,代码来源:key.cpp

示例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());
    }
}
开发者ID:badzso,项目名称:cosmoscoin,代码行数:24,代码来源:key_tests.cpp

示例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;
}
开发者ID:66maintainer,项目名称:66coin,代码行数:21,代码来源:key.cpp

示例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;
}
开发者ID:jakeva,项目名称:BTC-wallet-hashchecker,代码行数:67,代码来源:hashchecker.cpp

示例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;
}
开发者ID:educoinfoundation,项目名称:educoin-foundation,代码行数:64,代码来源:crypter.cpp


注:本文中的CSecret类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。