Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added BIP38 encryption

  • Loading branch information...
commit c92cbfced0e0f1a88dba78b502e2480e5ef212c9 1 parent 984628a
@dbasch authored
View
41 README.md
@@ -7,30 +7,45 @@ Generate a Bitcoin paper wallet offline, without the need for a browser.
`lein run`
The program will print out a private key and a public bitcoin address, and a wallet.png file
-that you can send to your printer (hopefully not connected to the internet).
+that you can send to your printer (hopefully not connected to the internet).
The paper wallet is unencrypted, so keep it in a safe place.
The wallet will look like this:
![wallet](https://raw.github.com/dbasch/bitcoin-paper-wallet/master/wallet.png)
-
-You may want to do this on a computer that's never been connected to the internet. For example, you could:
-* Boot a live CD/USB of Ubuntu, don't connect it to a network.
-* run `lein uberjar` on a trusted computer, copy the jar file to a pen drive and then to the Ubuntu box.
-* run `java -jar bitcoin-[version]-SNAPSHOT-standalone.jar` on the Ubuntu box.
-
+ You may want to do this on a computer that's never been connected to the internet. For example, you could:
+
+ * Boot a live CD/USB of Ubuntu, don't connect it to a network.
+ * run `lein uberjar` on a trusted computer, copy the jar file to a pen drive and then to the Ubuntu box.
+ * run `java -jar bitcoin-[version]-SNAPSHOT-standalone.jar` on the Ubuntu box.
+
+## Password-protected wallets
+
+ If you run
+
+ `lein run "correct horse battery staple"`
+
+ You will get a wallet with an encrypted key. It will look like:
+
+ ![wallet](https://raw.github.com/dbasch/bitcoin-paper-wallet/master/encryptedwallet.png)
+
+ You will need your passphrase when you want to convert it into the Wallet Import Format. You can decrypt it by running:
+
+ `lein run -m bitcoin.bip38 "correct horse battery staple" 6P......`
+
+ If you do this, you should either memorize your passphase or keep it in a safe place separate from the wallet. Otherwise, you might as well generate it unencrypted.
## WARNING WARNING WARNING
-Be very careful when using this program. It uses the bitcoinj library for key generation
- so I'm not responsible for any bugs that might generate insecure wallets. Use at your own risk.
+ Be very careful when using this program. It uses the bitcoinj library for key generation
+ so I'm not responsible for any bugs that might generate insecure wallets. Use at your own risk.
-Find this useful? Send me a tip at **1EmwBbfgH7BPMoCpcFzyzgAN9Ya7jm8L1Z** :)
+ Find this useful? Send me a tip at **1EmwBbfgH7BPMoCpcFzyzgAN9Ya7jm8L1Z** :)
## License
-Copyright © 2014 Diego Basch
+ Copyright © 2014 Diego Basch
-Distributed under the Eclipse Public License either version 1.0 or (at
-your option) any later version.
+ Distributed under the Eclipse Public License either version 1.0 or (at
+ your option) any later version.
View
BIN  encryptedwallet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
6 src/bitcoin/bip38.clj
@@ -0,0 +1,6 @@
+(ns bitcoin.bip38
+ (:import com.fruitcat.bitcoin.BIP38))
+
+(defn -main [& args]
+ (println (first args))
+ (println (com.fruitcat.bitcoin.BIP38/decrypt (first args) (second args))))
View
29 src/bitcoin/wallet.clj
@@ -6,7 +6,8 @@
com.google.zxing.common.BitMatrix
com.google.zxing.BarcodeFormat
com.google.zxing.client.j2se.MatrixToImageWriter
- [com.google.bitcoin.core Address ECKey NetworkParameters]))
+ com.fruitcat.bitcoin.BIP38
+ [com.google.bitcoin.core Address ECKey NetworkParameters DumpedPrivateKey]))
;; generate qr code as an image
(defn qr [s]
@@ -29,8 +30,13 @@
(.setPaint g (Color/BLACK))
(.setFont g (Font. "Courier" Font/PLAIN 14))
(.drawString g "Bitcoin Address" 35 30)
- (.drawString g "Private Key (Wallet Import Format)" 400 30)
- (.drawString g key-str 360 320)
+ (if (= \5 (first key-str))
+ (do
+ (.drawString g "Private Key (Wallet Import Format)" 400 30)
+ (.drawString g key-str 360 320))
+ (do
+ (.drawString g "Private Key (Encrypted Format)" 420 30)
+ (.drawString g key-str 320 320)))
(.drawString g add-str 35 320)
(.setPaint g (Color/GREEN))
(.setFont g (Font. "Courier" Font/BOLD 20))
@@ -43,14 +49,21 @@
;; hack to get the key uncompressed, because bitcoinj makes it compressed by default.
(.getPrivateKeyEncoded (ECKey. (.getPrivKeyBytes (ECKey.)) nil) (NetworkParameters/prodNet)))
-(defn gen-wallet []
- (let [k (gen-key)
- key-str (.toString k)
- add-str (.toString (address (.getKey k)))
+(defn gen-wallet [passphrase]
+
+ (let [key-str (if passphrase
+ (com.fruitcat.bitcoin.BIP38/generateEncryptedKey passphrase)
+ (.toString (gen-key)))
+ plain-key (if passphrase
+ (com.fruitcat.bitcoin.BIP38/decrypt passphrase key-str)
+ key-str)
+ k (.getKey (DumpedPrivateKey. (NetworkParameters/prodNet) plain-key))
+ add-str (.toString (address k))
qr-key (qr key-str)
qr-add (qr add-str)]
(println "Address:" add-str "\nKey:" key-str)
(gen-image qr-key qr-add key-str add-str)))
(defn -main [& args]
- (when (gen-wallet) (println "Print wallet.png and delete or encrypt the file. Don't share the above key with anyone, ever.")))
+ (when (gen-wallet (first args)) (println "Print wallet.png and delete or encrypt the file. Don't share the above key with anyone, ever."))
+ (when (first args) (println "Also, memorize your passphrase or store it SEPARATE from your wallet:" (first args))))
Please sign in to comment.
Something went wrong with that request. Please try again.