本文整理汇总了C++中OTPassword类的典型用法代码示例。如果您正苦于以下问题:C++ OTPassword类的具体用法?C++ OTPassword怎么用?C++ OTPassword使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OTPassword类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
String CryptoUtil::Base58CheckEncode(const OTData& input)
{
OTPassword transformedInput;
transformedInput.setMemory(input);
return Base58CheckEncode(transformedInput);
}
示例2: Mac_StoreSecret
// static
bool OTKeyring::Mac_StoreSecret(const OTString& strUser,
const OTPassword& thePassword,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
OT_ASSERT(thePassword.getMemorySize() > 0);
const std::string service_name = "opentxs";
const std::string account_name = strUser.Get();
OTMacKeychain theKeychain;
void* vData =
const_cast<void*>(static_cast<const void*>(thePassword.getMemory()));
OSStatus theError = theKeychain.AddSecret(
nullptr, service_name.size(), service_name.data(), account_name.size(),
account_name.data(), thePassword.getMemorySize(),
vData, // thePassword.getMemory()
nullptr);
if (theError != noErr) {
otErr
<< "OTKeyring::Mac_StoreSecret: Error in theKeychain.AddSecret.\n";
return false;
}
return true;
}
示例3: sizeof
serializedAsymmetricKey TrezorCrypto::HDNodeToSerialized(
const HDNode& node,
const DerivationMode privateVersion) const
{
serializedAsymmetricKey key = std::make_shared<proto::AsymmetricKey>();
key->set_version(1);
key->set_type(proto::AKEYTYPE_SECP256K1);
if (privateVersion) {
key->set_mode(proto::KEYMODE_PRIVATE);
key->set_chaincode(node.chain_code, sizeof(node.chain_code));
OTPassword plaintextKey;
plaintextKey.setMemory(node.private_key, sizeof(node.private_key));
OTData encryptedKey;
BinarySecret masterPassword(
App::Me().Crypto().AES().InstantiateBinarySecretSP());
masterPassword = CryptoSymmetric::GetMasterKey("");
bool encrypted = Libsecp256k1::EncryptPrivateKey(
plaintextKey,
*masterPassword,
encryptedKey);
if (encrypted) {
key->set_key(encryptedKey.GetPointer(), encryptedKey.GetSize());
}
} else {
key->set_mode(proto::KEYMODE_PUBLIC);
key->set_key(node.public_key, sizeof(node.public_key));
}
return key;
}
示例4: IOS_StoreSecret
// static
bool OTKeyring::IOS_StoreSecret(const OTString& strUser,
const OTPassword& thePassword,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
OT_ASSERT(thePassword.getMemorySize() > 0);
CFStringRef service_name = CFSTR("opentxs");
CFStringRef account_name = CFStringCreateWithCString(nullptr, strUser.Get(),
kCFStringEncodingUTF8);
CFDataRef vData = CFDataCreateWithBytesNoCopy(
nullptr, thePassword.getMemory_uint8(), thePassword.getMemorySize(),
kCFAllocatorNull);
const void* keys[] = {kSecClass, kSecAttrService, kSecAttrAccount,
kSecValueData};
const void* values[] = {kSecClassGenericPassword, service_name,
account_name, vData};
CFDictionaryRef item =
CFDictionaryCreate(nullptr, keys, values, 4, nullptr, nullptr);
OSStatus theError = SecItemAdd(item, nullptr);
CFRelease(item);
CFRelease(vData);
CFRelease(account_name);
if (theError != noErr) {
otErr << "OTKeyring::IOS_StoreSecret: Error in SecItemAdd.\n";
return false;
}
return true;
}
示例5: OT_ASSERT_MSG
serializedAsymmetricKey TrezorCrypto::SeedToPrivateKey(const OTPassword& seed)
const
{
serializedAsymmetricKey derivedKey;
HDNode node;
int result = ::hdnode_from_seed(
static_cast<const uint8_t*>(seed.getMemory()),
seed.getMemorySize(),
&node);
OT_ASSERT_MSG((1 == result), "Derivation of root node failed.");
if (1 == result) {
derivedKey = HDNodeToSerialized(node, TrezorCrypto::DERIVE_PRIVATE);
}
OTPassword root;
App::Me().Crypto().Hash().Digest(
CryptoHash::HASH160,
seed,
root);
derivedKey->mutable_path()->set_root(
root.getMemory(),
root.getMemorySize());
return derivedKey;
}
示例6: toWords
std::string TrezorCrypto::toWords(const OTPassword& seed) const
{
std::string wordlist(
::mnemonic_from_data(
static_cast<const uint8_t*>(seed.getMemory()),
seed.getMemorySize()));
return wordlist;
}
示例7: OT_ASSERT
std::string HDSeed::SaveSeed(
const OTPassword& words,
const OTPassword& passphrase) const
{
OT_ASSERT(words.isPassword() && passphrase.isPassword());
auto seed = aes_.InstantiateBinarySecretSP();
bip39_.WordsToSeed(words, *seed, passphrase);
OT_ASSERT(1 < seed->getMemorySize());
// the fingerprint is used as the identifier of the seed for indexing
// purposes. Always use the secp256k1 version for this.
auto fingerprint = bip32_.SeedToFingerprint(EcdsaCurve::SECP256K1, *seed);
const OTPasswordData reason("Encrypting a new BIP39 seed");
auto key = symmetric_.Key(reason, DEFAULT_ENCRYPTION_MODE);
OT_ASSERT(key.get());
proto::Seed serialized;
serialized.set_version(2);
serialized.set_index(0);
auto& encryptedWords = *serialized.mutable_words();
auto& encryptedPassphrase = *serialized.mutable_passphrase();
serialized.set_fingerprint(fingerprint);
auto empty = Data::Factory();
const bool haveWords = key->Encrypt(words, empty, reason, encryptedWords);
if (false == haveWords) {
otErr << OT_METHOD << __FUNCTION__ << ": Failed to encrypt seed."
<< std::endl;
return "";
}
bool havePassphrase =
key->Encrypt(passphrase, empty, reason, encryptedPassphrase, false);
if (!havePassphrase) {
otErr << OT_METHOD << __FUNCTION__ << ": Failed to encrypt passphrase."
<< std::endl;
return "";
}
const bool stored = storage_.Store(serialized, fingerprint);
if (!stored) {
otErr << OT_METHOD << __FUNCTION__ << ": Failed to store seed."
<< std::endl;
return "";
}
return fingerprint;
}
示例8: SetPrivateKey
bool Server::SetPrivateKey(const OTPassword& key) const
{
if (CURVE_KEY_BYTES != key.getMemorySize()) {
otErr << OT_METHOD << __FUNCTION__ << ": Invalid private key."
<< std::endl;
return false;
}
return set_private_key(key.getMemory(), key.getMemorySize());
}
示例9: SeedToData
bool HDSeed::SeedToData(
const OTPassword& words,
const OTPassword& passphrase,
OTPassword& output) const
{
OT_ASSERT(words.isPassword());
OT_ASSERT(passphrase.isPassword());
bip39_.WordsToSeed(words, output, passphrase);
return true;
}
示例10: qDebug
/**
* Try to unlock the wallet. If a passphrase is needed, a dialog is shown
* until the correct one is entered or the user cancels the action. In the
* latter case, UnlockFailure is thrown.
* @throws UnlockFailure if the user cancels the unlock.
*/
void
NMC_WalletUnlocker::unlock ()
{
std::string pwd;
qDebug () << "Trying to unlock the Namecoin wallet.";
/* If we need a password, show the dialog. */
if (nc.needWalletPassphrase ())
{
OTPassword otPwd;
MTDlgPassword dlg (nullptr, otPwd);
dlg.setDisplay ("Your Namecoin wallet is locked. For the operations to"
" proceed, please enter the passphrase to temporarily"
" unlock the wallet.");
const int res = dlg.exec ();
/* Return code is 0 for cancel button or closing the window.
It is 1 in case of ok. */
if (res == 0)
{
qDebug () << "Wallet unlock was cancelled.";
throw UnlockFailure("Wallet unlock was cancelled.");
}
dlg.extractPassword ();
pwd = otPwd.getPassword ();
}
/* Now try to unlock. If the passphrase is wrong, retry by a tail-recursive
call to unlock(). */
try
{
unlocker.unlock (pwd);
qDebug () << "Unlock successful (or not necessary).";
}
catch (const nmcrpc::NamecoinInterface::UnlockFailure& exc)
{
qDebug () << "Wrong passphrase, retrying.";
unlock ();
}
catch (const nmcrpc::JsonRpc::RpcError& exc)
{
qDebug () << "NMC RPC Error " << exc.getErrorCode ()
<< ": " << exc.getErrorMessage ().c_str ();
}
catch (const std::exception& exc)
{
qDebug () << "Error: " << exc.what ();
}
}
示例11: thePWData
// The highest-level possible interface (used by the API)
//
// NOTE: this version circumvents the master key.
OTPassword* LegacySymmetric::GetPassphraseFromUser(
const String& pstrDisplay,
bool bAskTwice) // returns a
// text
// OTPassword,
// or nullptr.
{
OTPassword* pPassUserInput =
OTPassword::CreateTextBuffer(); // already asserts.
// pPassUserInput->zeroMemory(); // This was causing the password to come
// out blank.
//
// Below this point, pPassUserInput must be returned, or deleted. (Or it
// will leak.)
const char* szDisplay = "LegacySymmetric::GetPassphraseFromUser";
OTPasswordData thePWData(
(!pstrDisplay.Exists()) ? szDisplay : pstrDisplay.Get());
// -------------------------------------------------------------------
//
// OLD SYSTEM! (NO MASTER KEY INVOLVEMENT.)
//
thePWData.setUsingOldSystem(); // So the cached key doesn't interfere,
// since
// this is for a plain symmetric key.
// -------------------------------------------------------------------
const auto& native = dynamic_cast<const api::internal::Native&>(OT::App());
auto* callback = native.GetInternalPasswordCallback();
const std::int32_t nCallback = (*callback)(
pPassUserInput->getPasswordWritable_char(),
pPassUserInput->getBlockSize(),
bAskTwice ? 1 : 0,
static_cast<void*>(&thePWData));
const std::uint32_t uCallback = static_cast<uint32_t>(nCallback);
if ((nCallback > 0) && // Success retrieving the passphrase from the user.
pPassUserInput->SetSize(uCallback)) {
// otOut << "%s: Retrieved passphrase (blocksize %d, actual size
// %d) from "
// "user: %s\n", __FUNCTION__,
// pPassUserInput->getBlockSize(), nCallback,
// pPassUserInput->getPassword());
return pPassUserInput; // Caller MUST delete!
} else {
delete pPassUserInput;
pPassUserInput = nullptr;
otOut
<< __FUNCTION__
<< ": Sorry, unable to retrieve passphrase from user. (Failure.)\n";
}
return nullptr;
}
示例12: Nonce
String CryptoUtil::Nonce(const uint32_t size, OTData& rawOutput) const
{
rawOutput.zeroMemory();
rawOutput.SetSize(size);
OTPassword source;
source.randomizeMemory(size);
String nonce(Base58CheckEncode(source));
rawOutput.Assign(source.getMemory(), source.getMemorySize());
return nonce;
}
示例13: Gnome_StoreSecret
// static
bool OTKeyring::Gnome_StoreSecret(const OTString& strUser,
const OTPassword& thePassword,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
OT_ASSERT(thePassword.getMemorySize() > 0);
OTData theData(thePassword.getMemory(), thePassword.getMemorySize());
OTASCIIArmor ascData(theData);
theData.zeroMemory(); // security reasons.
OTString strOutput;
const bool bSuccess =
ascData.Exists() &&
ascData.WriteArmoredString(strOutput, "DERIVED KEY"); // There's no
// default, to
// force you to
// enter the right
// string.
ascData.zeroMemory();
GnomeKeyringResult theResult = GNOME_KEYRING_RESULT_IO_ERROR;
if (bSuccess && strOutput.Exists()) {
theResult = gnome_keyring_store_password_sync(
GNOME_KEYRING_NETWORK_PASSWORD,
GNOME_KEYRING_DEFAULT, // GNOME_KEYRING_SESSION,
str_display.c_str(), strOutput.Get(), "user", strUser.Get(),
"protocol", "opentxs", // todo: hardcoding.
nullptr);
strOutput.zeroMemory();
bool bResult = false;
if (theResult == GNOME_KEYRING_RESULT_OK)
bResult = true;
else
otErr << "OTKeyring::Gnome_StoreSecret: "
<< "Failure in gnome_keyring_store_password_sync: "
<< gnome_keyring_result_to_message(theResult) << '\n';
return bResult;
}
otOut << "OTKeyring::Gnome_StoreSecret: No secret to store.\n";
return false;
}
示例14: Mac_RetrieveSecret
// static
bool OTKeyring::Mac_RetrieveSecret(const OTString& strUser,
OTPassword& thePassword,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
const std::string service_name = "opentxs";
const std::string account_name = strUser.Get();
uint32_t password_length = 0;
void* password_data = nullptr;
OTMacKeychain theKeychain;
OSStatus theError = theKeychain.FindSecret(
nullptr, service_name.size(), service_name.data(), account_name.size(),
account_name.data(), &password_length, // output.
&password_data, nullptr);
if (theError == noErr) {
thePassword.setMemory(password_data, password_length);
theKeychain.ItemFreeContent(nullptr, password_data);
return true;
}
else
otErr << "OTKeyring::Mac_RetrieveSecret: Error in "
"theKeychain.FindSecret.\n";
return false;
}
示例15: IOS_RetrieveSecret
// static
bool OTKeyring::IOS_RetrieveSecret(const OTString& strUser,
OTPassword& thePassword,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
CFStringRef service_name = CFSTR("opentxs");
CFStringRef account_name = CFStringCreateWithCString(nullptr, strUser.Get(),
kCFStringEncodingUTF8);
CFDataRef vData = nullptr;
const void* keys[] = {kSecClass, kSecAttrService, kSecAttrAccount,
kSecReturnData};
const void* values[] = {kSecClassGenericPassword, service_name,
account_name, kCFBooleanTrue};
CFDictionaryRef query =
CFDictionaryCreate(nullptr, keys, values, 4, nullptr, nullptr);
OSStatus theError = SecItemCopyMatching(query, (CFTypeRef*)&vData);
CFRelease(query);
CFRelease(account_name);
if (theError != noErr) {
otErr
<< "OTKeyring::IOS_RetrieveSecret: Error in SecItemCopyMatching.\n";
return false;
}
thePassword.setMemory(CFDataGetBytePtr(vData), CFDataGetLength(vData));
CFRelease(vData);
return true;
}