importing file

This commit is contained in:
Henry Varona 2016-12-01 07:49:16 -04:30
parent a4a5b85860
commit 5b08e2fe36

View file

@ -3,6 +3,7 @@ package com.luminiasoft.bitshares;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.luminiasoft.bitshares.crypto.AndroidRandomSource;
import com.luminiasoft.bitshares.crypto.SecureRandomStrengthener; import com.luminiasoft.bitshares.crypto.SecureRandomStrengthener;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -61,7 +62,7 @@ public abstract class FileBin {
try { try {
byte[] encKey = new byte[32]; byte[] encKey = new byte[32];
SecureRandomStrengthener randomStrengthener = SecureRandomStrengthener.getInstance(); SecureRandomStrengthener randomStrengthener = SecureRandomStrengthener.getInstance();
//randomStrengthener.addEntropySource(new AndroidRandomSource()); randomStrengthener.addEntropySource(new AndroidRandomSource());
SecureRandom secureRandom = randomStrengthener.generateAndSeedRandomNumberGenerator(); SecureRandom secureRandom = randomStrengthener.generateAndSeedRandomNumberGenerator();
secureRandom.nextBytes(encKey); secureRandom.nextBytes(encKey);
byte[] encKey_enc = encryptAES(encKey, password.getBytes("UTF-8")); byte[] encKey_enc = encryptAES(encKey, password.getBytes("UTF-8"));
@ -98,7 +99,6 @@ public abstract class FileBin {
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) {
@ -156,28 +156,33 @@ public abstract class FileBin {
} }
return null; return null;
} }
public static byte[] decompressDataLZMA(byte[] inputBytes) { private static byte[] decryptAES(byte[] input, byte[] key) {
LZMAInputStream in = null;
try { try {
ByteArrayInputStream input = new ByteArrayInputStream(inputBytes); MessageDigest md = MessageDigest.getInstance("SHA-512");
ByteArrayOutputStream output = new ByteArrayOutputStream(2048); byte[] result = md.digest(key);
in = new LZMAInputStream(input); byte[] ivBytes = new byte[16];
int size; System.arraycopy(result, 32, ivBytes, 0, 16);
while ((size = in.read()) != -1) { byte[] sksBytes = new byte[32];
output.write(size); System.arraycopy(result, 0, sksBytes, 0, 32);
} PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
in.close(); cipher.init(false, new ParametersWithIV(new KeyParameter(sksBytes), ivBytes));
return output.toByteArray(); byte[] out = new byte[cipher.getOutputSize(input.length)];
} catch (IOException ex) { int proc = cipher.processBytes(input, 0, input.length, out, 0);
} finally { cipher.doFinal(out, proc);
try {
in.close(); //Unpadding
} catch (IOException ex) { 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)));
temp = new byte[out.length - 16];
System.arraycopy(out, 0, temp, 0, temp.length);
return temp;
} catch (NoSuchAlgorithmException | DataLengthException | IllegalStateException | InvalidCipherTextException ex) {
} }
return null; return null;
} }
public static String byteToString(byte[] input) { public static String byteToString(byte[] input) {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();