Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing outdated imports (bitcoinj) and reenabling gradle jar build #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git/**
.gradle/**
build/**
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ A Java implementation of the BIP-0038 Draft: [Passphrase-protected private key](

`BIP38.decrypt(password, encryptedKey)` yields the decrypted get.

## Compiling to runnable JAR (using Linux)

1. Install gradle

`sudo apt-get install gradle`

2. Execute

`gradle clean jar`

3. Runnable jar is in build/libs

`java -jar BIP38.jar`

## Example

Key generation:
Expand Down
36 changes: 17 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,32 @@ apply plugin: 'application'
mainClassName = 'com.fruitcat.bitcoin.BIP38'

repositories {
mavenCentral()
maven {
url "http://distribution.bitcoinj.googlecode.com/git/releases/"
}
}

task fatJar(type: Jar) {
from files(sourceSets.main.output.classesDir)
from {configurations.compile.collect {zipTree(it)}} {
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
mavenCentral()
}

dependencies {
compile 'com.madgag:scprov-jdk15on:1.47.0.3'
compile 'com.google.guava:guava:15.0'
compile 'com.google:bitcoinj:0.10.3'
compile 'org.bouncycastle:bcprov-jdk16:1.46'
compile 'org.bitcoinj:bitcoinj-core:0.14.3'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
compile group: 'org.bouncycastle', name: 'bcprov-jdk16', version: '1.46'
testCompile 'org.testng:testng:6.8.7'
}

test {
useTestNG()
jar {
manifest {
attributes 'Main-Class': mainClassName
}
from configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}

test {
useTestNG()
}

manifest {
attributes 'Main-Class': 'com.fruitcat.bitcoin.BIP38'
}
}
attributes 'Main-Class': mainClassName
}
8 changes: 5 additions & 3 deletions src/main/java/com/fruitcat/bitcoin/BIP38.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

package com.fruitcat.bitcoin;

import com.google.bitcoin.core.*;
import com.google.bitcoin.params.MainNetParams;
import org.bitcoinj.core.*;
import org.bitcoinj.params.MainNetParams;
import com.lambdaworks.crypto.SCrypt;
import org.bouncycastle.asn1.sec.SECNamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters;
Expand Down Expand Up @@ -300,7 +300,9 @@ public static String decryptEC(String passphrase, byte[] encryptedKey) throws Un
BigInteger n = CURVE.getN();
BigInteger pk = new BigInteger(1, passFactor).multiply(new BigInteger(1, factorB)).remainder(n);

ECKey privKey = new ECKey(pk, null);
// Old way, deprecated
// ECKey privKey = new ECKey(pk, null);
ECKey privKey = ECKey.fromPrivate(pk);
return privKey.getPrivateKeyEncoded(params).toString();
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/fruitcat/bitcoin/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package com.fruitcat.bitcoin;

import com.google.bitcoin.core.AddressFormatException;
import com.google.bitcoin.core.Base58;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Base58;
import org.bouncycastle.math.ec.ECPoint;

import javax.crypto.Cipher;
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/fruitcat/bitcoin/BIP38Test.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.fruitcat.bitcoin;

import com.google.bitcoin.core.Base58;
import com.google.bitcoin.params.MainNetParams;
import org.bitcoinj.core.Base58;
import org.testng.annotations.Test;

import java.util.Arrays;
Expand Down