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


C++ OTPassword::zeroMemory方法代码示例

本文整理汇总了C++中OTPassword::zeroMemory方法的典型用法代码示例。如果您正苦于以下问题:C++ OTPassword::zeroMemory方法的具体用法?C++ OTPassword::zeroMemory怎么用?C++ OTPassword::zeroMemory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OTPassword的用法示例。


在下文中一共展示了OTPassword::zeroMemory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetPasswordFromConsole

bool CryptoUtil::GetPasswordFromConsole(OTPassword& theOutput, bool bRepeat) const
{
    int32_t nAttempts = 0;

    for (;;) {
        theOutput.zeroMemory();

        if (GetPasswordFromConsole(theOutput, "(OT) passphrase: ")) {
            if (!bRepeat) {
                std::cout << std::endl;
                return true;
            }
        }
        else {
            std::cout << "Sorry." << std::endl;
            return false;
        }

        OTPassword tempPassword;

        if (!GetPasswordFromConsole(tempPassword,
                                            "(Verifying) passphrase again: ")) {
            std::cout << "Sorry." << std::endl;
            return false;
        }

        if (!tempPassword.Compare(theOutput)) {
            if (++nAttempts >= 3) break;

            std::cout << "(Mismatch, try again.)\n" << std::endl;
        }
        else {
            std::cout << std::endl;
            return true;
        }
    }

    std::cout << "Sorry." << std::endl;

    return false;
}
开发者ID:Kodachi75,项目名称:opentxs,代码行数:41,代码来源:CryptoUtil.cpp

示例2: LoadMainFile

bool MainFile::LoadMainFile(bool bReadOnly)
{
    if (!OTDB::Exists(".", server_->m_strWalletFilename.Get())) {
        Log::vError("%s: Error finding file: %s\n", __FUNCTION__,
                    server_->m_strWalletFilename.Get());
        return false;
    }
    String strFileContents(OTDB::QueryPlainString(
        ".",
        server_->m_strWalletFilename.Get())); // <=== LOADING FROM DATA STORE.

    if (!strFileContents.Exists()) {
        Log::vError("%s: Unable to read main file: %s\n", __FUNCTION__,
                    server_->m_strWalletFilename.Get());
        return false;
    }

    bool bNeedToSaveAgain = false;

    bool bFailure = false;

    {
        OTStringXML xmlFileContents(strFileContents);

        if (false ==
            xmlFileContents.DecodeIfArmored()) // bEscapedIsAllowed=true by
                                               // default.
        {
            Log::vError("%s: Notary server file apparently was encoded and "
                        "then failed decoding. Filename: %s \n"
                        "Contents: \n%s\n",
                        __FUNCTION__, server_->m_strWalletFilename.Get(),
                        strFileContents.Get());
            return false;
        }
        irr::io::IrrXMLReader* xml =
            irr::io::createIrrXMLReader(xmlFileContents);
        std::unique_ptr<irr::io::IrrXMLReader> theXMLGuardian(xml);
        while (xml && xml->read()) {
            // strings for storing the data that we want to read out of the file

            String AssetName;
            String InstrumentDefinitionID;

            const String strNodeName(xml->getNodeName());

            switch (xml->getNodeType()) {
            case irr::io::EXN_TEXT:
                // in this xml file, the only text which occurs is the
                // messageText
                // messageText = xml->getNodeData();
                break;
            case irr::io::EXN_ELEMENT: {
                if (strNodeName.Compare("notaryServer")) {
                    version_ = xml->getAttributeValue("version");
                    server_->m_strNotaryID = xml->getAttributeValue("notaryID");
                    server_->m_strServerNymID =
                        xml->getAttributeValue("serverNymID");

                    String strTransactionNumber; // The server issues
                                                 // transaction numbers and
                                                 // stores the counter here
                                                 // for the latest one.
                    strTransactionNumber =
                        xml->getAttributeValue("transactionNum");
                    server_->transactor_.transactionNumber(
                        strTransactionNumber.ToLong());

                    Log::vOutput(
                        0,
                        "\nLoading Open Transactions server. File version: %s\n"
                        " Last Issued Transaction Number: %" PRId64
                        "\n Notary ID:     "
                        " %s\n Server Nym ID: %s\n",
                        version_.c_str(),
                        server_->transactor_.transactionNumber(),
                        server_->m_strNotaryID.Get(),
                        server_->m_strServerNymID.Get());

                }
                // todo in the future just remove masterkey. I'm leaving it for
                // now so people's
                // data files can get converted over. After a while just remove
                // it.
                //
                else if (strNodeName.Compare("masterKey") ||
                         strNodeName.Compare("cachedKey")) {
                    OTASCIIArmor ascCachedKey;

                    if (Contract::LoadEncodedTextField(xml, ascCachedKey)) {
                        // We successfully loaded the masterKey from file, so
                        // let's SET it
                        // as the master key globally...
                        //
                        OTCachedKey::It()->SetCachedKey(ascCachedKey);

                        if (!OTCachedKey::It()->HasHashCheck()) {
                            OTPassword tempPassword;
                            tempPassword.zeroMemory();
                            std::shared_ptr<OTCachedKey> sharedPtr(
//.........这里部分代码省略.........
开发者ID:bitcredit-currency,项目名称:opentxs,代码行数:101,代码来源:MainFile.cpp

示例3: CreateMainFile

bool MainFile::CreateMainFile(const std::string& strContract,
                              const std::string& strNotaryID,
                              const std::string& strCert,
                              const std::string& strNymID,
                              const std::string& strCachedKey)
{
    if (!OTDB::StorePlainString(strContract, "contracts", strNotaryID)) {
        Log::Error("Failed trying to store the server contract.\n");
        return false;
    }

    if (!strCert.empty() &&
        !OTDB::StorePlainString(strCert, "certs", strNymID)) {
        Log::Error(
            "Failed trying to store the server Nym's public/private cert.\n");
        return false;
    }

    const char* szBlankFile = // todo hardcoding.
        "<notaryServer version=\"2.0\"\n"
        " notaryID=\"%s\"\n"
        " serverNymID=\"%s\"\n"
        " transactionNum=\"%ld\" >\n"
        "\n"
        "<cachedKey>\n"
        "%s</cachedKey>\n"
        "\n"
        "<accountList type=\"voucher\" count=\"0\" >\n"
        "\n"
        "</accountList>\n"
        "\n"
        "</notaryServer>\n\n";

    int64_t lTransNum = 5; // a starting point, for the new server.

    String strNotaryFile;
    strNotaryFile.Format(szBlankFile, strNotaryID.c_str(), strNymID.c_str(),
                         lTransNum, strCachedKey.c_str());

    std::string str_Notary(strNotaryFile.Get());

    if (!OTDB::StorePlainString(str_Notary, ".",
                                "notaryServer.xml")) // todo hardcoding.
    {
        Log::Error("Failed trying to store the new notaryServer.xml file.\n");
        return false;
    }
    OTASCIIArmor ascCachedKey;
    ascCachedKey.Set(strCachedKey.c_str());
    OTCachedKey::It()->SetCachedKey(ascCachedKey);

    if (!OTCachedKey::It()->HasHashCheck()) {
        OTPassword tempPassword;
        tempPassword.zeroMemory();
        std::shared_ptr<OTCachedKey> sharedPtr(OTCachedKey::It());
        sharedPtr->GetMasterPassword(
            sharedPtr, tempPassword,
            "We do not have a check hash yet for this password, "
            "please enter your password",
            true);
        if (!SaveMainFile()) {
            OT_FAIL;
        }
    }
    // At this point, the contract is saved, the cert is saved, and the
    // notaryServer.xml file
    // is saved. All we have left is the Nymfile, which we'll create.

    const String strServerNymID(strNymID.c_str());

    server_->m_nymServer.SetIdentifier(strServerNymID);

    if (!server_->m_nymServer.LoadCredentials(true)) {
        Log::vOutput(0, "%s: Error loading server credentials, or "
                        "certificate and private key.\n",
                     __FUNCTION__);
    }
    else if (!server_->m_nymServer.VerifyPseudonym()) {
        Log::vOutput(0, "%s: Error verifying server nym. Are you sure you "
                        "have the right ID?\n",
                     __FUNCTION__);
    }
    else if (!server_->m_nymServer.SaveSignedNymfile(server_->m_nymServer)) {
        Log::vOutput(0, "%s: Error saving new nymfile for server nym.\n",
                     __FUNCTION__);
    }
    else {
        Log::vOutput(0, "%s: OKAY, we have apparently created the new "
                        "server.\n"
                        "Let's try to load up your new server contract...\n",
                     __FUNCTION__);
        return true;
    }

    return false;
}
开发者ID:bitcredit-currency,项目名称:opentxs,代码行数:96,代码来源:MainFile.cpp

示例4: GetMasterPassword


//.........这里部分代码省略.........
				bReturnVal = true; // Success.
			}
			else // It didn't unlock with the one we found.
			{
				OTLog::vOutput(0, "%s: Unable to unlock master key using derived key found on system keyring.\n", szFunc);
				delete pDerivedKey;
				pDerivedKey = NULL;  // Below, this function checks pDerivedKey for NULL.
			}
		}
		else    // NOT found on keyring.
		{
			if (this->IsUsingSystemKeyring()) // We WERE using the keying, but we DIDN'T find the derived key.
				OTLog::vOutput(1, "%s: Unable to find derived key on system keyring.\n", szFunc);
			// (Otherwise if we WEREN'T using the system keyring, then of course we didn't find any derived key cached there.)
			delete pDerivedKey;
			pDerivedKey = NULL; // Below, this function checks pDerivedKey for NULL.

		}
	}
	// --------------------------------------------------    
	// NOT found on Keyring...
	//
	if (NULL == pDerivedKey) // Master key was not cached in OT, nor was it found in the system keychain.
	{                        // Therefore we HAVE to ask the user for a passphrase and decrypt it ourselves,
		// since we DO have an encrypted version of the key...

		// This time we DEFINITELY force the user input, since we already played our hand.
		// If the master key was still in memory we would have returned already, above.
		// Then we tried to find it on the keyring and we couldn't find it, so now we have
		// to actually ask the user to enter it.
		//

		std::string default_password(OT_DEFAULT_PASSWORD); // default password
		OTPassword passwordDefault; passwordDefault.zeroMemory(); passwordDefault.setPassword(default_password.c_str(),static_cast<int>(default_password.length()));

		OTPassword passUserInput;  passUserInput.zeroMemory(); // text mode.
		OTPasswordData  thePWData(str_display.c_str(), &passUserInput, this); // these pointers are only passed in the case where it's for a master key.
//      OTLog::vOutput(2, "*********Begin OTCachedKey::GetMasterPassword: Calling souped-up password cb...\n * *  * *  * *  * *  * ");
		// -----------------------------------------------------------------------


		// It's possible this is the first time this is happening, and the master key 
		// hasn't even been generated yet. In which case, we generate it here...
		//
		bool bGenerated = m_pSymmetricKey->IsGenerated();

		if (!bGenerated) // This Symmetric Key hasn't been generated before....
		{

			if (!OTAsymmetricKey::GetPasswordCallback()(NULL, 0, bVerifyTwice ? 1 : 0, static_cast<void *>(&thePWData)))
			{
				OTLog::vError("%s: Failed to get password from user!", __FUNCTION__);
				return false;
			}


			// If the length of the user supplied password is less than 4 characters long, we are going to use the default password!
			bool bUsingDefaultPassword = false;
			{
				if (4 > std::string(passUserInput.getPassword()).length())
				{
					OTLog::vOutput(0, "\n Password entered was less than 4 characters long! This is NOT secure!!\n"
						"... Assuming password is for testing only... setting to default password: %s \n",
						OT_DEFAULT_PASSWORD);
					bUsingDefaultPassword = true;
				}
开发者ID:9cat,项目名称:Open-Transactions,代码行数:67,代码来源:OTCachedKey.cpp


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