Skip to content
Browse files

added bip38 encryption

  • Loading branch information...
1 parent 17c1aba commit b8b34c169717a0ea86708cd63b11c4ef0d155df9 @dbasch committed Jan 24, 2014
Showing with 62 additions and 20 deletions.
  1. +20 −3 README.md
  2. BIN encryptedwallet.png
  3. +1 −1 project.clj
  4. +8 −0 src/dogecoin/bip38.clj
  5. +33 −16 src/dogecoin/wallet.clj
View
23 README.md
@@ -6,7 +6,7 @@ Generate a Dogecoin 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
+The program will print out a private key and a public dogecoin address, and a wallet.png file
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.
@@ -18,11 +18,28 @@ The wallet will look like this:
* 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.
+ * run `java -jar dogecoin-[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/dogecoin-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 dogecoin.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 [dogecoinj](https://github.com/langerhans/dogecoinj-new) library for key generation
+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 **DHpZsQCDKq9WbqyqfetMcGq87pFZfkwLBh** :)
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
2 project.clj
@@ -3,7 +3,7 @@
:url "http://diegobasch.com"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
- :dependencies [[org.clojars.dbasch/dogecoinj "0.11"]
+ :dependencies [[org.clojars.dbasch/bip38 "0.1.1"]
[com.madgag/scprov-jdk15on "1.47.0.3"]
[com.google.guava/guava "15.0"]
[org.slf4j/slf4j-api "1.7.5"]
View
8 src/dogecoin/bip38.clj
@@ -0,0 +1,8 @@
+(ns dogecoin.bip38
+ (:require dogecoin.wallet)
+ (:import com.fruitcat.bitcoin.BIP38))
+
+(defn -main [& args]
+ (com.fruitcat.bitcoin.BIP38/setNetParams (dogecoin.wallet/np))
+ (println (first args))
+ (println (com.fruitcat.bitcoin.BIP38/decrypt (first args) (second args))))
View
49 src/dogecoin/wallet.clj
@@ -6,18 +6,25 @@
com.google.zxing.common.BitMatrix
com.google.zxing.BarcodeFormat
com.google.zxing.client.j2se.MatrixToImageWriter
- [com.google.dogecoin.core Address DumpedPrivateKey ECKey NetworkParameters]))
+ com.fruitcat.bitcoin.BIP38
+ [com.google.bitcoin.core Address DumpedPrivateKey ECKey NetworkParameters]))
;; generate qr code as an image
(defn qr [s]
(let [writer (QRCodeWriter.)
matrix (.encode writer s BarcodeFormat/QR_CODE 300 300)]
(MatrixToImageWriter/toBufferedImage matrix)))
+(defn np []
+ (proxy [com.google.bitcoin.params.MainNetParams] []
+ (get [] (np))
+ (getDumpedPrivateKeyHeader [] 158)
+ (getAddressHeader [] 30)))
+
(defn address [k]
- (.toAddress k (NetworkParameters/prodNet)))
+ (.toAddress k (np)))
-(defn gen-image [qr-key qr-add key-str add-str]
+(defn gen-image [qr-key qr-add key-str add-str passphrase]
;; I'm no artist, I just draw everything with absolute coordinates
;; in a way that looks ok for me.
(let [img (BufferedImage. 800 350 BufferedImage/TYPE_INT_RGB)
@@ -29,32 +36,42 @@
(.setPaint g (Color/BLACK))
(.setFont g (Font. "Courier" Font/PLAIN 14))
(.drawString g "Dogecoin Address" 35 30)
- (.drawString g "Private Key (Wallet Import Format)" 400 30)
- (.drawString g key-str 360 320)
+ (if passphrase
+ (do
+ (.drawString g "Private Key (Encrypted Format)" 420 30)
+ (.drawString g key-str 320 320))
+ (do
+ (.drawString g "Private Key (Wallet Import Format)" 400 30)
+ (.drawString g key-str 360 320)))
(.drawString g add-str 35 320)
(.setPaint g (Color/GREEN))
(.setFont g (Font. "Courier" Font/BOLD 20))
(.drawString g "SHARE" 210 30)
(.setPaint g (Color/RED))
(.drawString g "SECRET" 695 30)
- (javax.imageio.ImageIO/write img "png" (java.io.File. "wallet.png"))))
+ (javax.imageio.ImageIO/write img "png" (java.io.File. "dogewallet.png"))))
(defn gen-key []
- (.getPrivateKeyEncoded (ECKey.) (NetworkParameters/prodNet)))
-
-(defn gen-wallet []
- (let [k (gen-key)
- key-str (.toString k)
- p (NetworkParameters/prodNet)
- dk (DumpedPrivateKey. p key-str)
- add-str (.toString (.toAddress (.getKey dk) p))
+ (.getPrivateKeyEncoded (ECKey.) (np)))
+
+(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. (np) 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)))
+ (gen-image qr-key qr-add key-str add-str passphrase)))
(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.")))
+ (com.fruitcat.bitcoin.BIP38/setNetParams (np))
+ (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))))

0 comments on commit b8b34c1

Please sign in to comment.
Something went wrong with that request. Please try again.