exporting importing files
This commit is contained in:
parent
1e6bd3b7d3
commit
e1234fdd75
2 changed files with 21 additions and 31 deletions
|
@ -1,10 +1,8 @@
|
||||||
package com.luminiasoft.bitshares;
|
package com.luminiasoft.bitshares;
|
||||||
|
|
||||||
import com.google.common.primitives.Bytes;
|
|
||||||
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;
|
||||||
|
@ -16,11 +14,9 @@ import java.security.SecureRandom;
|
||||||
import java.util.Arrays;
|
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.bitcoinj.core.ECKey;
|
||||||
import org.spongycastle.crypto.DataLengthException;
|
import org.spongycastle.crypto.DataLengthException;
|
||||||
import org.spongycastle.crypto.InvalidCipherTextException;
|
import org.spongycastle.crypto.InvalidCipherTextException;
|
||||||
import org.spongycastle.crypto.digests.RIPEMD160Digest;
|
|
||||||
import org.spongycastle.crypto.engines.AESFastEngine;
|
import org.spongycastle.crypto.engines.AESFastEngine;
|
||||||
import org.spongycastle.crypto.modes.CBCBlockCipher;
|
import org.spongycastle.crypto.modes.CBCBlockCipher;
|
||||||
import org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
import org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
||||||
|
@ -64,54 +60,48 @@ 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 = 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[] encKey_enc = encryptAES(encKey, password.getBytes("UTF-8"));
|
||||||
byte[] encBrain = encryptAES(BrainKey.getBytes("ASCII"), encKey);
|
byte[] encBrain = encryptAES(BrainKey.getBytes("ASCII"), encKey);
|
||||||
|
|
||||||
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)));
|
||||||
|
|
||||||
JsonObject wallet_object = new JsonObject();
|
JsonObject wallet_object = new JsonObject();
|
||||||
wallet_object.add("wallet", wallet);
|
wallet_object.add("wallet", wallet);
|
||||||
JsonArray accountNames = new JsonArray();
|
JsonArray accountNames = new JsonArray();
|
||||||
JsonObject jsonAccountName = new JsonObject();
|
JsonObject jsonAccountName = new JsonObject();
|
||||||
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);
|
||||||
System.out.println(wallet_object.toString());
|
|
||||||
byte[] compressedData = compressDataLZMA(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);
|
||||||
byte[] rawData = new byte[compressedData.length + 4];
|
byte[] rawData = new byte[compressedData.length + 4];
|
||||||
System.arraycopy(checksum, 0, rawData, 0, 4);
|
System.arraycopy(checksum, 0, rawData, 0, 4);
|
||||||
System.arraycopy(compressedData, 0, rawData, 4, compressedData.length);
|
System.arraycopy(compressedData, 0, rawData, 4, compressedData.length);
|
||||||
|
|
||||||
byte[] passPrivKey = ECKey.fromPrivate(md.digest(password.getBytes("UTF-8"))).getPrivKeyBytes();
|
|
||||||
|
|
||||||
byte[] randomKey = new byte[32];
|
byte[] randomKey = new byte[32];
|
||||||
secureRandom.nextBytes(randomKey);
|
secureRandom.nextBytes(randomKey);
|
||||||
byte[] randPubKey = ECKey.fromPrivate(md.digest(randomKey)).getPubKey();
|
ECKey randomECKey = ECKey.fromPrivate(md.digest(randomKey));
|
||||||
|
byte[] randPubKey = randomECKey.getPubKey();
|
||||||
|
|
||||||
//System.out.println(byteToString(cipher.doFinal(encKey)));
|
byte[] finalKey = randomECKey.getPubKeyPoint().multiply(ECKey.fromPrivate(md.digest(password.getBytes("UTF-8"))).getPrivKey()).normalize().getXCoord().getEncoded();
|
||||||
// Cypher random public key with aespassword
|
|
||||||
// Cypher key ciphered key and aespassword
|
MessageDigest md1 = MessageDigest.getInstance("SHA-512");
|
||||||
// Cypher brainkey
|
finalKey = md1.digest(finalKey);
|
||||||
// Store cypher brainkey and cyher public + password
|
rawData = encryptAES(rawData, finalKey);
|
||||||
//LZMA compress
|
|
||||||
//Generate another public key
|
byte[] result = new byte[rawData.length + randPubKey.length];
|
||||||
//Cypher public key with password
|
System.arraycopy(randPubKey, 0, result, 0, randPubKey.length);
|
||||||
// result Cypher compressed message
|
System.arraycopy(rawData, 0, result, randPubKey.length, rawData.length);
|
||||||
return null;
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
return result;
|
||||||
Logger.getLogger(FileBin.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
} catch (UnsupportedEncodingException | NoSuchAlgorithmException ex) {
|
||||||
Logger.getLogger(FileBin.class.getName()).log(Level.SEVERE, null, ex);
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -156,7 +146,6 @@ public abstract class FileBin {
|
||||||
byte[] temp = new byte[input.length + (16 - (input.length % 16))];
|
byte[] temp = new byte[input.length + (16 - (input.length % 16))];
|
||||||
System.arraycopy(input, 0, temp, 0, input.length);
|
System.arraycopy(input, 0, temp, 0, input.length);
|
||||||
Arrays.fill(temp, input.length, temp.length, (byte) (16 - (input.length % 16)));
|
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)];
|
byte[] out = new byte[cipher.getOutputSize(temp.length)];
|
||||||
int proc = cipher.processBytes(temp, 0, temp.length, out, 0);
|
int proc = cipher.processBytes(temp, 0, temp.length, out, 0);
|
||||||
cipher.doFinal(out, proc);
|
cipher.doFinal(out, proc);
|
||||||
|
|
|
@ -725,6 +725,7 @@ public class Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateBinFile(){
|
public void testCreateBinFile(){
|
||||||
FileBin.getBytesFromBrainKey(Main.BRAIN_KEY, "123456","bithon-83");
|
byte[] fileOutput = FileBin.getBytesFromBrainKey(Main.BRAIN_KEY, "123456","bithon-83");
|
||||||
|
System.out.println("fileOutput " + Arrays.toString(fileOutput));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue