export bin file
This commit is contained in:
parent
7a904a435e
commit
5366ed4d82
3 changed files with 127 additions and 36 deletions
|
@ -1,10 +1,31 @@
|
||||||
package com.luminiasoft.bitshares;
|
package com.luminiasoft.bitshares;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Bytes;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import com.luminiasoft.bitshares.crypto.AndroidRandomSource;
|
||||||
|
import com.luminiasoft.bitshares.crypto.SecureRandomStrengthener;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import org.bitcoinj.core.Base58;
|
||||||
|
import org.bitcoinj.core.ECKey;
|
||||||
|
import org.spongycastle.crypto.DataLengthException;
|
||||||
|
import org.spongycastle.crypto.InvalidCipherTextException;
|
||||||
|
import org.spongycastle.crypto.digests.RIPEMD160Digest;
|
||||||
|
import org.spongycastle.crypto.engines.AESFastEngine;
|
||||||
|
import org.spongycastle.crypto.modes.CBCBlockCipher;
|
||||||
|
import org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
||||||
|
import org.spongycastle.crypto.params.KeyParameter;
|
||||||
|
import org.spongycastle.crypto.params.ParametersWithIV;
|
||||||
import org.tukaani.xz.LZMA2Options;
|
import org.tukaani.xz.LZMA2Options;
|
||||||
import org.tukaani.xz.LZMAInputStream;
|
import org.tukaani.xz.LZMAInputStream;
|
||||||
import org.tukaani.xz.LZMAOutputStream;
|
import org.tukaani.xz.LZMAOutputStream;
|
||||||
|
@ -38,10 +59,46 @@ public abstract class FileBin {
|
||||||
* @param password The pin code
|
* @param password The pin code
|
||||||
* @return The array byte of the file, or null if an error ocurred
|
* @return The array byte of the file, or null if an error ocurred
|
||||||
*/
|
*/
|
||||||
public static byte[] getBytesFromBrainKey(String BrainKey, String password) {
|
public static byte[] getBytesFromBrainKey(String BrainKey, String password, String accountName) {
|
||||||
|
|
||||||
// Cypher AES password
|
try {
|
||||||
// Get random public key address
|
byte[] encKey = new byte[32];
|
||||||
|
SecureRandomStrengthener randomStrengthener = SecureRandomStrengthener.getInstance();
|
||||||
|
randomStrengthener.addEntropySource(new AndroidRandomSource());
|
||||||
|
SecureRandom secureRandom = randomStrengthener.generateAndSeedRandomNumberGenerator();
|
||||||
|
secureRandom.nextBytes(encKey);
|
||||||
|
|
||||||
|
//byte[] encKey = new byte[]{(byte) 23, (byte) 216, (byte) 129, (byte) 104, (byte) 115, (byte) 250, (byte) 179, (byte) 214, (byte) 64, (byte) 173, (byte) 173, (byte) 145, (byte) 251, (byte) 234, (byte) 25, (byte) 189, (byte) 20, (byte) 227, (byte) 239, (byte) 103, (byte) 226, (byte) 39, (byte) 145, (byte) 234, (byte) 12, (byte) 104, (byte) 91, (byte) 73, (byte) 76, (byte) 151, (byte) 47, (byte) 210};
|
||||||
|
byte[] encKey_enc = encryptAES(encKey, password.getBytes("UTF-8"));
|
||||||
|
byte[] encBrain = encryptAES(BrainKey.getBytes("ASCII"), encKey);
|
||||||
|
|
||||||
|
JsonObject wallet = new JsonObject();
|
||||||
|
wallet.add("encryption_key", new JsonParser().parse(byteToString(encKey_enc)));
|
||||||
|
wallet.add("encrypted_brainkey", new JsonParser().parse(byteToString(encBrain)));
|
||||||
|
|
||||||
|
JsonObject wallet_object = new JsonObject();
|
||||||
|
wallet_object.add("wallet", wallet);
|
||||||
|
JsonArray accountNames = new JsonArray();
|
||||||
|
JsonObject jsonAccountName = new JsonObject();
|
||||||
|
jsonAccountName.add("name", new JsonParser().parse(accountName));
|
||||||
|
accountNames.add(jsonAccountName);
|
||||||
|
|
||||||
|
wallet_object.add("linked_accounts", accountNames);
|
||||||
|
System.out.println(wallet_object.toString());
|
||||||
|
byte[] compressedData = compressDataLZMA(wallet_object.toString().getBytes("UTF-8"));
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
|
byte[] checksum = md.digest(compressedData);
|
||||||
|
byte[] rawData = new byte[compressedData.length + 4];
|
||||||
|
System.arraycopy(checksum, 0, rawData, 0, 4);
|
||||||
|
System.arraycopy(compressedData, 0, rawData, 4, compressedData.length);
|
||||||
|
|
||||||
|
byte[] passPrivKey = ECKey.fromPrivate(md.digest(password.getBytes("UTF-8"))).getPrivKeyBytes();
|
||||||
|
|
||||||
|
byte[] randomKey = new byte[32];
|
||||||
|
secureRandom.nextBytes(randomKey);
|
||||||
|
byte[] randPubKey = ECKey.fromPrivate(md.digest(randomKey)).getPubKey();
|
||||||
|
|
||||||
|
//System.out.println(byteToString(cipher.doFinal(encKey)));
|
||||||
// Cypher random public key with aespassword
|
// Cypher random public key with aespassword
|
||||||
// Cypher key ciphered key and aespassword
|
// Cypher key ciphered key and aespassword
|
||||||
// Cypher brainkey
|
// Cypher brainkey
|
||||||
|
@ -51,6 +108,12 @@ public abstract class FileBin {
|
||||||
//Cypher public key with password
|
//Cypher public key with password
|
||||||
// result Cypher compressed message
|
// result Cypher compressed message
|
||||||
return null;
|
return null;
|
||||||
|
} catch (UnsupportedEncodingException ex) {
|
||||||
|
Logger.getLogger(FileBin.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
|
Logger.getLogger(FileBin.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] compressDataLZMA(byte[] inputBytes) {
|
public static byte[] compressDataLZMA(byte[] inputBytes) {
|
||||||
|
@ -59,7 +122,7 @@ public abstract class FileBin {
|
||||||
ByteArrayInputStream input = new ByteArrayInputStream(inputBytes);
|
ByteArrayInputStream input = new ByteArrayInputStream(inputBytes);
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream(2048);
|
ByteArrayOutputStream output = new ByteArrayOutputStream(2048);
|
||||||
LZMA2Options options = new LZMA2Options();
|
LZMA2Options options = new LZMA2Options();
|
||||||
out = new LZMAOutputStream(output, options,-1);
|
out = new LZMAOutputStream(output, options, -1);
|
||||||
byte[] buf = new byte[inputBytes.length];
|
byte[] buf = new byte[inputBytes.length];
|
||||||
int size;
|
int size;
|
||||||
while ((size = input.read(buf)) != -1) {
|
while ((size = input.read(buf)) != -1) {
|
||||||
|
@ -79,6 +142,39 @@ public abstract class FileBin {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static byte[] encryptAES(byte[] input, byte[] key) {
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-512");
|
||||||
|
byte[] result = md.digest(key);
|
||||||
|
byte[] ivBytes = new byte[16];
|
||||||
|
System.arraycopy(result, 32, ivBytes, 0, 16);
|
||||||
|
byte[] sksBytes = new byte[32];
|
||||||
|
System.arraycopy(result, 0, sksBytes, 0, 32);
|
||||||
|
|
||||||
|
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
|
||||||
|
cipher.init(true, new ParametersWithIV(new KeyParameter(sksBytes), ivBytes));
|
||||||
|
byte[] temp = new byte[input.length + (16 - (input.length % 16))];
|
||||||
|
System.arraycopy(input, 0, temp, 0, input.length);
|
||||||
|
Arrays.fill(temp, input.length, temp.length, (byte) (16 - (input.length % 16)));
|
||||||
|
System.out.println(byteToString(temp));
|
||||||
|
byte[] out = new byte[cipher.getOutputSize(temp.length)];
|
||||||
|
int proc = cipher.processBytes(temp, 0, temp.length, out, 0);
|
||||||
|
cipher.doFinal(out, proc);
|
||||||
|
temp = new byte[out.length - 16];
|
||||||
|
System.arraycopy(out, 0, temp, 0, temp.length);
|
||||||
|
return temp;
|
||||||
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} catch (DataLengthException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} catch (IllegalStateException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} catch (InvalidCipherTextException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] decompressDataLZMA(byte[] inputBytes) {
|
public static byte[] decompressDataLZMA(byte[] inputBytes) {
|
||||||
LZMAInputStream in = null;
|
LZMAInputStream in = null;
|
||||||
try {
|
try {
|
||||||
|
@ -102,4 +198,15 @@ public abstract class FileBin {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String byteToString(byte[] input) {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (byte in : input) {
|
||||||
|
if ((in & 0xff) < 0x10) {
|
||||||
|
result.append("0");
|
||||||
|
}
|
||||||
|
result.append(Integer.toHexString(in & 0xff));
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,20 +5,18 @@ import org.bitcoinj.core.ECKey;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
// Brain key from Nelson's app referencing the bilthon-83 account
|
// Brain key from Nelson's app referencing the bilthon-83 account
|
||||||
public static final String BRAIN_KEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH";
|
public static final String BRAIN_KEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH";
|
||||||
|
|
||||||
//public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER";
|
//public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER";
|
||||||
//public static final String BRAIN_KEY = "SIVER TIKKER FOGO HOMINAL PRAYER LUTEIN SMALLY ACARID MEROPIA TRANCE BOGONG IDDAT HICKORY SOUTANE MOOD DOWSER";
|
//public static final String BRAIN_KEY = "SIVER TIKKER FOGO HOMINAL PRAYER LUTEIN SMALLY ACARID MEROPIA TRANCE BOGONG IDDAT HICKORY SOUTANE MOOD DOWSER";
|
||||||
|
|
||||||
public static final String BIP39_KEY = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
|
public static final String BIP39_KEY = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
|
||||||
|
|
||||||
// WIF from Nelson's app referencing the bilthon-83 account
|
// WIF from Nelson's app referencing the bilthon-83 account
|
||||||
// public static final String WIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM";
|
// public static final String WIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM";
|
||||||
|
|
||||||
// Brain key from an empty account created by the cli_wallet
|
// Brain key from an empty account created by the cli_wallet
|
||||||
// public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER";
|
// public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER";
|
||||||
|
|
||||||
// WIF from an emty account created by the cli_wallet
|
// WIF from an emty account created by the cli_wallet
|
||||||
public static final String WIF = "5KMzB2GqGhnh7ufhgddmz1eKPHS72uTLeL9hHjSvPb1UywWknF5";
|
public static final String WIF = "5KMzB2GqGhnh7ufhgddmz1eKPHS72uTLeL9hHjSvPb1UywWknF5";
|
||||||
|
|
||||||
|
@ -39,43 +37,25 @@ public class Main {
|
||||||
// } catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// test.testCustomSerializer();
|
// test.testCustomSerializer();
|
||||||
|
|
||||||
// test.testTransactionSerialization();
|
// test.testTransactionSerialization();
|
||||||
|
|
||||||
// test.testLoginSerialization();
|
// test.testLoginSerialization();
|
||||||
|
|
||||||
// test.testNetworkBroadcastSerialization();
|
// test.testNetworkBroadcastSerialization();
|
||||||
|
|
||||||
// test.testNetworkBroadcastDeserialization();
|
// test.testNetworkBroadcastDeserialization();
|
||||||
|
|
||||||
// test.testGetDynamicParams();
|
// test.testGetDynamicParams();
|
||||||
|
|
||||||
// test.testGetRequiredFeesSerialization();
|
// test.testGetRequiredFeesSerialization();
|
||||||
|
|
||||||
// test.testRequiredFeesResponse();
|
// test.testRequiredFeesResponse();
|
||||||
|
|
||||||
// test.testTransactionBroadcastSequence();
|
// test.testTransactionBroadcastSequence();
|
||||||
|
|
||||||
// test.testAccountLookupDeserialization();
|
// test.testAccountLookupDeserialization();
|
||||||
|
|
||||||
// test.testPrivateKeyManipulations();
|
// test.testPrivateKeyManipulations();
|
||||||
|
|
||||||
// test.testGetAccountByName();
|
// test.testGetAccountByName();
|
||||||
|
|
||||||
// test.testGetRequiredFees();
|
// test.testGetRequiredFees();
|
||||||
|
|
||||||
// test.testRandomNumberGeneration();
|
// test.testRandomNumberGeneration();
|
||||||
|
|
||||||
// test.testBrainKeyOperations(false);
|
// test.testBrainKeyOperations(false);
|
||||||
|
|
||||||
// test.testBip39Opertion();
|
// test.testBip39Opertion();
|
||||||
|
//test.testAccountNamebyAddress();
|
||||||
test.testAccountNamebyAddress();
|
|
||||||
|
|
||||||
// test.testAccountNameById();
|
// test.testAccountNameById();
|
||||||
|
|
||||||
// test.testRelativeAccountHistory();
|
// test.testRelativeAccountHistory();
|
||||||
|
test.testCreateBinFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -705,4 +705,8 @@ public class Test {
|
||||||
System.out.println("NoSuchAlgorithmException. Msg: " + e.getMessage());
|
System.out.println("NoSuchAlgorithmException. Msg: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCreateBinFile(){
|
||||||
|
FileBin.getBytesFromBrainKey(Main.BRAIN_KEY, "123456","bithon-83");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue