<ol>
<li>Yes, you can encrypt the wallet</li>
</ol>

<blockquote>
  <p>It’s a good idea to encrypt your private keys if you only spend money from your wallet rarely. The Wallet.encrypt("password") method will derive an AES key from an Scrypt hash of the given password string and use it to encrypt the private keys in the wallet, you can then provide the password when signing transactions or to fully decrypt the wallet. You can also provide your own AES keys if you don’t want to derive them from a password, and you can also customize the Scrypt hash parameters.</p>
</blockquote>

<ol start="2">
<li>Yes, you can corrupt the wallet, but not if you do things the right way.</li>
</ol>

<blockquote>
  <p>By default the Wallet is just an in-memory object, it won’t save by itself. You can use saveToFile() or saveToOutputStream() when you want to persist the wallet. It’s best to use saveToFile() if possible because this will write to a temporary file and then atomically rename it, giving you assurance that the wallet won’t be half-written or corrupted if something goes wrong half way through the saving process.</p>
</blockquote>

<p>Source: <a href="https://bitcoinj.github.io/working-with-the-wallet" rel="nofollow noreferrer">https://bitcoinj.github.io/working-with-the-wallet</a></p>

CC BY-SA 4.0
2019-01-04T12:05:10.460Z
2019-01-04T15:23:26.763Z
2019-01-04T15:23:26.763Z
RedGrittyBrick
<p>I am a new <code>BitcoinJ</code> user, I have few questions related about its wallet, can anyone please help:</p>

<ol>
<li><p>Is there any way to encrypt the .wallet file? will anyone obtain a copy of the file be able to spend all bitcoin in it?</p></li>
<li><p>Is there a chance of damaging the file if I stop my application often or incorrectly?</p></li>
</ol>

<p>Thanks a lot.</p>

<wallet><bitcoinj>
How to protect bitcoinj wallet?
Luong Nguyen
# How to protect bitcoinj wallet?

(Asked by: username_0 on 2019-01-04)

I am a new `BitcoinJ` user, I have few questions related about its wallet, can anyone please help:

1. Is there any way to encrypt the .wallet file? will anyone obtain a copy of the file be able to spend all bitcoin in it?
2. Is there a chance of damaging the file if I stop my application often or incorrectly?

Thanks a lot.

**Tags:** wallet, bitcoinj


---

## 1 answers

### Answer by username_1 on 2019-01-04. Score: 2 | Accepted answer

1. Yes, you can encrypt the wallet

> It’s a good idea to encrypt your private keys if you only spend money from your wallet rarely. The Wallet.encrypt("password") method will derive an AES key from an Scrypt hash of the given password string and use it to encrypt the private keys in the wallet, you can then provide the password when signing transactions or to fully decrypt the wallet. You can also provide your own AES keys if you don’t want to derive them from a password, and you can also customize the Scrypt hash parameters.

2. Yes, you can corrupt the wallet, but not if you do things the right way.

> By default the Wallet is just an in-memory object, it won’t save by itself. You can use saveToFile() or saveToOutputStream() when you want to persist the wallet. It’s best to use saveToFile() if possible because this will write to a temporary file and then atomically rename it, giving you assurance that the wallet won’t be half-written or corrupted if something goes wrong half way through the saving process.

Source: <https://bitcoinj.github.io/working-with-the-wallet>


---

