Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: andrecalabrese on April 12, 2020, 07:55:23 AM



Title: Merging two encrypted wallet.dat files
Post by: andrecalabrese on April 12, 2020, 07:55:23 AM
I have a technical question.

A wallet is protected by a password, which encrypts the key.

Is it possible to "merge" two encrypted wallets into one and have a completely new database, if they are encrypted with the same password?

Is there any paper on how the encryption works?


Title: Re: Merging two encrypted wallet.dat files
Post by: HeRetiK on April 12, 2020, 08:42:52 AM
I have a technical question.

A wallet is protected by a password, which encrypts the key.

Is it possible to "merge" two encrypted wallets into one and have a completely new database, if they are encrypted with the same password?

Is there any paper on how the encryption works?

Two different encrypted wallets will be encrypted using two different keys, even if they have the same password. As you mentioned yourself, the key is encrypted using the password. Accordingly the wallet itself is not encrypted using the password but the randomly generated key that is encrypted using said password.

Bitcoin Core's wallet.dat uses standard ciphers and hashing algorithms. See here for reference:
https://en.bitcoin.it/wiki/Wallet_encryption

Information on AES-256 and SHA-512 itself is widely available. It is not possible to "merge" AES-256 encrypted data without decrypting it first, even if they are encrypted using the same key.





Title: Re: Merging two encrypted wallet.dat files
Post by: pooya87 on April 12, 2020, 09:32:00 AM
what is it exactly that you are trying to do? there is a good chance that there is a more logical and better way of achieving that. for instance wallets usually support "importing" keys which is the option you should use if you want to "merge" another wallet into a wallet you have if the software allowed that. but a still better way is to  "sweep" the keys into the wallet that you have which means sending the coins from the secondary wallet keys to the primary wallet.


Title: Re: Merging two encrypted wallet.dat files
Post by: koch44 on April 12, 2020, 01:43:45 PM
I have a technical question.

A wallet is protected by a password, which encrypts the key.

Is it possible to "merge" two encrypted wallets into one and have a completely new database, if they are encrypted with the same password?

Is there any paper on how the encryption works?

First you would need to know if the DB is same version, otherwise you would need to convert it yourself.

This is possible in blockchain.com wallets (to have multiple xpriv) but as someone said above, it would probably mean you would break backward compatibility and would have your own custom bitcoin core version not readable by other versions.


Title: Re: Merging two encrypted wallet.dat files
Post by: R.I.U. iol on April 14, 2020, 04:39:31 PM
I don't know if this helps, but you can:
export the private keys from both wallets
then create a new wallet
import both private keys into the new wallet
your new wallet will have all the addresses of the two old wallets


Title: Re: Merging two encrypted wallet.dat files
Post by: nc50lc on April 16, 2020, 07:32:13 AM
You'd lose HD wallet feature, which force you to backup wallet.dat file regularly. OP apparently trying to merge multiple wallet.dat without losing any features or advantage each wallet.dat have.
He will only need to backup once after he imported the keys or dumpwallet file.
After that, the 'new backup' can still generate the new/future addresses/keys as long as the hdseed is the same.
Old backups however wont contain the imported prv keys.

I don't know if this helps, but you can:
export the private keys from both wallets
Better use dumpwallet (https://bitcoincore.org/en/doc/0.19.0/rpc/wallet/dumpwallet/) on wallet1, then importwallet (https://bitcoincore.org/en/doc/0.19.0/rpc/wallet/importwallet/) the dump file to wallet2.
That's doable within a minute if you're fast, minus the rescan.


Title: Re: Merging two encrypted wallet.dat files
Post by: HCP on April 16, 2020, 11:08:15 PM
I have a technical question.

A wallet is protected by a password, which encrypts the key.

Is it possible to "merge" two encrypted wallets into one and have a completely new database, if they are encrypted with the same password?

Is there any paper on how the encryption works?
Which wallet application are you referring to? ??? As not all wallets use the same encryption methods/standards. Are both wallets from the same app?

I suspect this is an "XY problem (https://en.wikipedia.org/wiki/XY_problem). What are you actually wanting to achieve by merging two wallets together? ??? What is your specific scenario/reason for wanting to "merge" 2 wallets? ???


Title: Re: Merging two encrypted wallet.dat files
Post by: keychainX on April 26, 2020, 12:00:23 AM
I have a technical question.

A wallet is protected by a password, which encrypts the key.

Is it possible to "merge" two encrypted wallets into one and have a completely new database, if they are encrypted with the same password?

Is there any paper on how the encryption works?

No you cannot, as there is no wallet that can have multiple passwords for different private keys.

All wallets even those with imported keys share the same password, therefor render it impossible to "merge" two different wallets with different passwords into one.

If you need info on password encryption for bitcoin core you could always dive in here; (google AES-256-CBC and SHA-512)

https://en.bitcoin.it/wiki/Wallet_encryption

/KX


Title: Re: Merging two encrypted wallet.dat files
Post by: cryptoworld99 on May 04, 2020, 02:04:11 AM
Yes, its possible.


bitcoin-cli createwallet "testwallet"

This should make a folder called "testwallet" in your bitcoin dir

delete the wallet.dat file there and upload your encrypted wallet.dat file there

to spend funds from what wallet.dat file you do this

bitcoin-cli loadwallet testwallet

bitcoin-cli -rpcwallet=testwallet sendtoaddress (address) (amount)

Easy as that, repeat step 1 as many times as you like with as many wallet.dat files.


Learn more here: https://bitcoincore.org/en/doc/0.17.0/rpc/wallet/createwallet/

Good luck PM me if you need any help.


Title: Re: Merging two encrypted wallet.dat files
Post by: ranochigo on May 04, 2020, 02:42:29 AM
-snip-
You're sweeping the funds from one wallet file to another. OP wants to merge two of his wallet.dat such that the addresses from both wallet.dat is in one wallet.dat only.


Title: Re: Merging two encrypted wallet.dat files
Post by: cryptoworld99 on May 04, 2020, 04:30:11 AM
-snip-
You're sweeping the funds from one wallet file to another. OP wants to merge two of his wallet.dat such that the addresses from both wallet.dat is in one wallet.dat only.


-snip-
You're sweeping the funds from one wallet file to another. OP wants to merge two of his wallet.dat such that the addresses from both wallet.dat is in one wallet.dat only.



Hmmmm.


Try this:

Re-run bitcoind/Bitcoin-Qt, giving the -wallet=/path/to/wallet option.
dumpwallet the private keys to a file
Shutdown.
concatenate the files together.
Re-run and importwallet the combined file.