Skip to content

Commit

Permalink
added bip38 encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
dbasch committed Jan 24, 2014
1 parent 17c1aba commit b8b34c1
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 20 deletions.
23 changes: 20 additions & 3 deletions README.md
Expand Up @@ -6,7 +6,7 @@ Generate a Dogecoin paper wallet offline, without the need for a browser.


lein run 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). 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 paper wallet is unencrypted, so keep it in a safe place.


Expand All @@ -18,11 +18,28 @@ The wallet will look like this:


* Boot a live CD/USB of Ubuntu, don't connect it to a network. * 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 `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 ## 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. 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** :) Find this useful? send me a tip at **DHpZsQCDKq9WbqyqfetMcGq87pFZfkwLBh** :)
Expand Down
Binary file added encryptedwallet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion project.clj
Expand Up @@ -3,7 +3,7 @@
:url "http://diegobasch.com" :url "http://diegobasch.com"
:license {:name "Eclipse Public License" :license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"} :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.madgag/scprov-jdk15on "1.47.0.3"]
[com.google.guava/guava "15.0"] [com.google.guava/guava "15.0"]
[org.slf4j/slf4j-api "1.7.5"] [org.slf4j/slf4j-api "1.7.5"]
Expand Down
8 changes: 8 additions & 0 deletions 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))))
49 changes: 33 additions & 16 deletions src/dogecoin/wallet.clj
Expand Up @@ -6,18 +6,25 @@
com.google.zxing.common.BitMatrix com.google.zxing.common.BitMatrix
com.google.zxing.BarcodeFormat com.google.zxing.BarcodeFormat
com.google.zxing.client.j2se.MatrixToImageWriter 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 ;; generate qr code as an image
(defn qr [s] (defn qr [s]
(let [writer (QRCodeWriter.) (let [writer (QRCodeWriter.)
matrix (.encode writer s BarcodeFormat/QR_CODE 300 300)] matrix (.encode writer s BarcodeFormat/QR_CODE 300 300)]
(MatrixToImageWriter/toBufferedImage matrix))) (MatrixToImageWriter/toBufferedImage matrix)))


(defn np []
(proxy [com.google.bitcoin.params.MainNetParams] []
(get [] (np))
(getDumpedPrivateKeyHeader [] 158)
(getAddressHeader [] 30)))

(defn address [k] (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 ;; I'm no artist, I just draw everything with absolute coordinates
;; in a way that looks ok for me. ;; in a way that looks ok for me.
(let [img (BufferedImage. 800 350 BufferedImage/TYPE_INT_RGB) (let [img (BufferedImage. 800 350 BufferedImage/TYPE_INT_RGB)
Expand All @@ -29,32 +36,42 @@
(.setPaint g (Color/BLACK)) (.setPaint g (Color/BLACK))
(.setFont g (Font. "Courier" Font/PLAIN 14)) (.setFont g (Font. "Courier" Font/PLAIN 14))
(.drawString g "Dogecoin Address" 35 30) (.drawString g "Dogecoin Address" 35 30)
(.drawString g "Private Key (Wallet Import Format)" 400 30) (if passphrase
(.drawString g key-str 360 320) (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) (.drawString g add-str 35 320)
(.setPaint g (Color/GREEN)) (.setPaint g (Color/GREEN))
(.setFont g (Font. "Courier" Font/BOLD 20)) (.setFont g (Font. "Courier" Font/BOLD 20))
(.drawString g "SHARE" 210 30) (.drawString g "SHARE" 210 30)
(.setPaint g (Color/RED)) (.setPaint g (Color/RED))
(.drawString g "SECRET" 695 30) (.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 [] (defn gen-key []
(.getPrivateKeyEncoded (ECKey.) (NetworkParameters/prodNet))) (.getPrivateKeyEncoded (ECKey.) (np)))


(defn gen-wallet [] (defn gen-wallet [passphrase]
(let [k (gen-key) (let [key-str (if passphrase
key-str (.toString k) (com.fruitcat.bitcoin.BIP38/generateEncryptedKey passphrase)
p (NetworkParameters/prodNet) (.toString (gen-key)))
dk (DumpedPrivateKey. p key-str) plain-key (if passphrase
add-str (.toString (.toAddress (.getKey dk) p)) (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-key (qr key-str)
qr-add (qr add-str)] qr-add (qr add-str)]
(println "Address:" add-str "\nKey:" key-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] (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))))






Expand Down

0 comments on commit b8b34c1

Please sign in to comment.