exporting importing files
This commit is contained in:
parent
a505e29cea
commit
a4a5b85860
2 changed files with 12 additions and 20 deletions
|
@ -53,7 +53,8 @@ public abstract class FileBin {
|
||||||
*
|
*
|
||||||
* @param BrainKey The input brainkey
|
* @param BrainKey The input brainkey
|
||||||
* @param password The pin code
|
* @param password The pin code
|
||||||
* @return The array byte of the file, or null if an error ocurred
|
* @param accountName The Account Name
|
||||||
|
* @return The array byte of the file, or null if an error happens
|
||||||
*/
|
*/
|
||||||
public static byte[] getBytesFromBrainKey(String BrainKey, String password, String accountName) {
|
public static byte[] getBytesFromBrainKey(String BrainKey, String password, String accountName) {
|
||||||
|
|
||||||
|
@ -66,6 +67,9 @@ public abstract class FileBin {
|
||||||
byte[] encKey_enc = encryptAES(encKey, password.getBytes("UTF-8"));
|
byte[] encKey_enc = encryptAES(encKey, password.getBytes("UTF-8"));
|
||||||
byte[] encBrain = encryptAES(BrainKey.getBytes("ASCII"), encKey);
|
byte[] encBrain = encryptAES(BrainKey.getBytes("ASCII"), encKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data to Store
|
||||||
|
*/
|
||||||
JsonObject wallet = new JsonObject();
|
JsonObject wallet = new JsonObject();
|
||||||
wallet.add("encryption_key", new JsonParser().parse(byteToString(encKey_enc)));
|
wallet.add("encryption_key", new JsonParser().parse(byteToString(encKey_enc)));
|
||||||
wallet.add("encrypted_brainkey", new JsonParser().parse(byteToString(encBrain)));
|
wallet.add("encrypted_brainkey", new JsonParser().parse(byteToString(encBrain)));
|
||||||
|
@ -76,7 +80,6 @@ public abstract class FileBin {
|
||||||
jsonAccountName.add("name", new JsonParser().parse(accountName));
|
jsonAccountName.add("name", new JsonParser().parse(accountName));
|
||||||
accountNames.add(jsonAccountName);
|
accountNames.add(jsonAccountName);
|
||||||
wallet_object.add("linked_accounts", accountNames);
|
wallet_object.add("linked_accounts", accountNames);
|
||||||
|
|
||||||
byte[] compressedData = Util.compress(wallet_object.toString().getBytes("UTF-8"));
|
byte[] compressedData = Util.compress(wallet_object.toString().getBytes("UTF-8"));
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
byte[] checksum = md.digest(compressedData);
|
byte[] checksum = md.digest(compressedData);
|
||||||
|
@ -87,21 +90,19 @@ public abstract class FileBin {
|
||||||
secureRandom.nextBytes(randomKey);
|
secureRandom.nextBytes(randomKey);
|
||||||
ECKey randomECKey = ECKey.fromPrivate(md.digest(randomKey));
|
ECKey randomECKey = ECKey.fromPrivate(md.digest(randomKey));
|
||||||
byte[] randPubKey = randomECKey.getPubKey();
|
byte[] randPubKey = randomECKey.getPubKey();
|
||||||
|
|
||||||
byte[] finalKey = randomECKey.getPubKeyPoint().multiply(ECKey.fromPrivate(md.digest(password.getBytes("UTF-8"))).getPrivKey()).normalize().getXCoord().getEncoded();
|
byte[] finalKey = randomECKey.getPubKeyPoint().multiply(ECKey.fromPrivate(md.digest(password.getBytes("UTF-8"))).getPrivKey()).normalize().getXCoord().getEncoded();
|
||||||
|
|
||||||
MessageDigest md1 = MessageDigest.getInstance("SHA-512");
|
MessageDigest md1 = MessageDigest.getInstance("SHA-512");
|
||||||
finalKey = md1.digest(finalKey);
|
finalKey = md1.digest(finalKey);
|
||||||
rawData = encryptAES(rawData, finalKey);
|
rawData = encryptAES(rawData, byteToString(finalKey).getBytes());
|
||||||
|
|
||||||
byte[] result = new byte[rawData.length + randPubKey.length];
|
byte[] result = new byte[rawData.length + randPubKey.length];
|
||||||
System.arraycopy(randPubKey, 0, result, 0, randPubKey.length);
|
System.arraycopy(randPubKey, 0, result, 0, randPubKey.length);
|
||||||
System.arraycopy(rawData, 0, result, randPubKey.length, rawData.length);
|
System.arraycopy(rawData, 0, result, randPubKey.length, rawData.length);
|
||||||
|
|
||||||
|
System.out.println("result : " + byteToString(result));
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
} catch (UnsupportedEncodingException | NoSuchAlgorithmException ex) {
|
} catch (UnsupportedEncodingException | NoSuchAlgorithmException ex) {
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +141,6 @@ public abstract class FileBin {
|
||||||
System.arraycopy(result, 32, ivBytes, 0, 16);
|
System.arraycopy(result, 32, ivBytes, 0, 16);
|
||||||
byte[] sksBytes = new byte[32];
|
byte[] sksBytes = new byte[32];
|
||||||
System.arraycopy(result, 0, sksBytes, 0, 32);
|
System.arraycopy(result, 0, sksBytes, 0, 32);
|
||||||
|
|
||||||
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
|
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
|
||||||
cipher.init(true, new ParametersWithIV(new KeyParameter(sksBytes), ivBytes));
|
cipher.init(true, new ParametersWithIV(new KeyParameter(sksBytes), ivBytes));
|
||||||
byte[] temp = new byte[input.length + (16 - (input.length % 16))];
|
byte[] temp = new byte[input.length + (16 - (input.length % 16))];
|
||||||
|
@ -152,14 +152,7 @@ public abstract class FileBin {
|
||||||
temp = new byte[out.length - 16];
|
temp = new byte[out.length - 16];
|
||||||
System.arraycopy(out, 0, temp, 0, temp.length);
|
System.arraycopy(out, 0, temp, 0, temp.length);
|
||||||
return temp;
|
return temp;
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
} catch (NoSuchAlgorithmException | DataLengthException | IllegalStateException | InvalidCipherTextException ex) {
|
||||||
ex.printStackTrace();
|
|
||||||
} catch (DataLengthException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} catch (IllegalStateException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} catch (InvalidCipherTextException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -177,12 +170,10 @@ public abstract class FileBin {
|
||||||
in.close();
|
in.close();
|
||||||
return output.toByteArray();
|
return output.toByteArray();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(FileBin.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(FileBin.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import org.tukaani.xz.XZOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class used to encapsulate common utility methods
|
* Class used to encapsulate common utility methods
|
||||||
|
@ -43,12 +44,12 @@ public class Util {
|
||||||
* @author Henry Varona
|
* @author Henry Varona
|
||||||
*/
|
*/
|
||||||
public static byte[] compress(byte[] inputBytes) {
|
public static byte[] compress(byte[] inputBytes) {
|
||||||
LZMAOutputStream out = null;
|
XZOutputStream out = null;
|
||||||
try {
|
try {
|
||||||
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 XZOutputStream(output, options);
|
||||||
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) {
|
||||||
|
|
Loading…
Reference in a new issue