From 577af21b676ebecdd0f3a396ce8a0ab4a0943935 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Wed, 1 Feb 2017 12:42:43 -0500 Subject: [PATCH] Using LZMA for bin backup decompression to try to solve the compatibility issue --- .../de/bitsharesmunich/graphenej/FileBin.java | 25 ++++++++++++++++--- .../de/bitsharesmunich/graphenej/Main.java | 8 +++--- .../de/bitsharesmunich/graphenej/Test.java | 4 +-- .../de/bitsharesmunich/graphenej/Util.java | 9 ++++--- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/bitsharesmunich/graphenej/FileBin.java b/src/main/java/de/bitsharesmunich/graphenej/FileBin.java index 281a574..b23c685 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/FileBin.java +++ b/src/main/java/de/bitsharesmunich/graphenej/FileBin.java @@ -4,6 +4,10 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import de.bitsharesmunich.graphenej.crypto.SecureRandomStrengthener; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.math.BigInteger; import java.security.MessageDigest; @@ -42,13 +46,28 @@ public abstract class FileBin { MessageDigest md1 = MessageDigest.getInstance("SHA-512"); finalKey = md1.digest(finalKey); byte[] rawData = Util.decryptAES(rawDataEncripted, Util.byteToString(finalKey).getBytes()); - + + try { + FileOutputStream out = new FileOutputStream("/Users/nelson/Development/Java/Fullerene/src/main/java/de/bitsharesmunich/graphenej/decrypted.bin"); + out.write(rawData); + out.close(); + } catch (FileNotFoundException e) { + System.out.println("FileNotFoundException. Msg: "+e.getMessage()); + } catch (IOException e) { + System.out.println("IOException. Msg: "+e.getMessage()); + } + + byte[] checksum = new byte[4]; System.arraycopy(rawData, 0, checksum, 0, 4); byte[] compressedData = new byte[rawData.length - 4]; System.arraycopy(rawData, 4, compressedData, 0, compressedData.length); - - byte[] wallet_object_bytes = Util.decompress(compressedData, Util.XZ); + + System.out.println("raw: "+Util.bytesToHex(rawData)); + System.out.println("checksum: "+Util.bytesToHex(checksum)); + System.out.println("compressed: "+Util.bytesToHex(compressedData)); + + byte[] wallet_object_bytes = Util.decompress(rawData, Util.LZMA); String wallet_string = new String(wallet_object_bytes, "UTF-8"); JsonObject wallet = new JsonParser().parse(wallet_string).getAsJsonObject(); if (wallet.get("wallet").isJsonArray()) { diff --git a/src/main/java/de/bitsharesmunich/graphenej/Main.java b/src/main/java/de/bitsharesmunich/graphenej/Main.java index a56442e..bf6074d 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/Main.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Main.java @@ -17,6 +17,8 @@ public class Main { public static final String WIF = "5KMzB2GqGhnh7ufhgddmz1eKPHS72uTLeL9hHjSvPb1UywWknF5"; + public static final String BILTHON_83_PASSWORD = System.getenv("BILTHON_83_PASSWORD"); + // Static block information used for transaction serialization tests public static int REF_BLOCK_NUM = 56204; public static int REF_BLOCK_PREFIX = 1614747814; @@ -59,8 +61,8 @@ public class Main { // test.testAccountUpdateSerialization(); // test.testAccountUpdateOperationBroadcast(); // test.testCreateBinFile(); -// test.testImportBinFile(); -// test.testLookupAccounts(); + test.testImportBinFile(); +// test.testLookupAccounts(); // test.testLookupAccounts(); // test.testDecodeMemo(); // test.testGetRelativeAccountHistory(); @@ -74,6 +76,6 @@ public class Main { // test.testGetMarketHistory(); // test.testGetAccountBalances(); // test.testGetAssetHoldersCount(); - test.testSubscription(null); +// test.testSubscription(null); } } diff --git a/src/main/java/de/bitsharesmunich/graphenej/Test.java b/src/main/java/de/bitsharesmunich/graphenej/Test.java index 237cc25..c771ae7 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/Test.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Test.java @@ -632,11 +632,11 @@ public class Test { public void testImportBinFile() { try { String current = new File(".").getCanonicalPath(); - File file = new File(current + "/src/main/java/de/bitsharesmunich/graphenej/bts_bilthon_20161218.bin"); + File file = new File(current + "/src/main/java/de/bitsharesmunich/graphenej/bts_bilthon-83_20170131.bin"); Path path = Paths.get(file.getAbsolutePath()); byte[] data = Files.readAllBytes(path); - System.out.println(FileBin.getBrainkeyFromByte(data, "123456")); + String brainKey = FileBin.getBrainkeyFromByte(data, Main.BILTHON_83_PASSWORD); } catch (IOException e) { System.out.println("IOException while trying to open bin file. Msg: "+e.getMessage()); } diff --git a/src/main/java/de/bitsharesmunich/graphenej/Util.java b/src/main/java/de/bitsharesmunich/graphenej/Util.java index c43b684..5897d23 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/Util.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Util.java @@ -140,10 +140,11 @@ public class Util { } catch (IOException ex) { Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex); } finally { - try { - in.close(); - } catch (IOException ex) { - Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex); } +// try { +// in.close(); +// } catch (IOException ex) { +// Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex); +// } } return null; }