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;
}
Пример #2
0
bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
{
    LOCK(cs_KeyStore);
    if (!mapCryptedKeys.empty() || IsCrypted())
        return false;

    fUseCrypto = true;
    for (KeyMap::value_type& mKey : mapKeys)
    {
        const CKey &key = mKey.second;
        CPubKey vchPubKey = key.GetPubKey();
        CKeyingMaterial vchSecret(key.begin(), key.end());
        std::vector<unsigned char> vchCryptedSecret;
        if (!EncryptSecret(vMasterKeyIn, vchSecret, vchPubKey.GetHash(), vchCryptedSecret))
            return false;
        if (!AddCryptedKey(vchPubKey, vchCryptedSecret))
            return false;
    }
    mapKeys.clear();
    return true;
}
Пример #3
0
std::string AdvancedCrypt(std::string boinchash)
{

	try 
	{
	   std::vector<unsigned char> vchSecret( boinchash.begin(), boinchash.end() );
	   std::string d1 = "                                                                                                                                        ";
	   std::vector<unsigned char> vchCryptedSecret(d1.begin(),d1.end());
       bool OK = GridEncrypt(vchSecret, vchCryptedSecret);
	   std::string encrypted = UnsignedVectorToString(vchCryptedSecret);
	   return encrypted;
	} catch (std::exception &e) 
	{
		printf("Error while encrypting %s",boinchash.c_str());
		return "";
	}
	catch(...)
	{
		printf("Error while encrypting 2.");
		return "";
	}
              
}
Пример #4
0
std::string AdvancedCrypt(std::string boinchash)
{

    try
    {
       std::vector<unsigned char> vchSecret( boinchash.begin(), boinchash.end() );
       std::vector<unsigned char> vchCryptedSecret;
       GridEncrypt(vchSecret, vchCryptedSecret);
       std::string encrypted = EncodeBase64(UnsignedVectorToString(vchCryptedSecret));
       return encrypted;
    }
    catch (std::exception &e)
    {
        LogPrintf("Error while encrypting %s",boinchash);
        return "";
    }
    catch(...)
    {
        LogPrintf("Error while encrypting 2.");
        return "";
    }

}