| 455 | } |
| 456 | |
| 457 | bool CWallet::Unlock(const SecureString& strWalletPassphrase, bool accept_no_keys) |
| 458 | { |
| 459 | CCrypter crypter; |
| 460 | CKeyingMaterial _vMasterKey; |
| 461 | |
| 462 | { |
| 463 | LOCK(cs_wallet); |
| 464 | for (const MasterKeyMap::value_type& pMasterKey : mapMasterKeys) |
| 465 | { |
| 466 | if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) |
| 467 | return false; |
| 468 | if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey)) |
| 469 | continue; // try another master key |
| 470 | if (Unlock(_vMasterKey, accept_no_keys)) { |
| 471 | // Now that we've unlocked, upgrade the key metadata |
| 472 | UpgradeKeyMetadata(); |
| 473 | // Now that we've unlocked, upgrade the descriptor cache |
| 474 | UpgradeDescriptorCache(); |
| 475 | return true; |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | return false; |
| 480 | } |
| 481 | |
| 482 | bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase) |
| 483 | { |