exporting importing files

This commit is contained in:
Henry Varona 2016-11-28 11:27:57 -04:30
parent f539e8951d
commit 7a904a435e
2 changed files with 106 additions and 35 deletions

View file

@ -12,4 +12,5 @@ dependencies {
compile 'com.neovisionaries:nv-websocket-client:1.30'
compile 'org.bitcoinj:bitcoinj-core:0.14.3'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile group: "org.tukaani", name: "xz", version: "1.6"
}

View file

@ -1,35 +1,105 @@
package com.luminiasoft.bitshares;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.tukaani.xz.LZMA2Options;
import org.tukaani.xz.LZMAInputStream;
import org.tukaani.xz.LZMAOutputStream;
/**
* Class to manage the Bin Files
*
* @author Henry Varona
*/
public abstract class FileBin {
/**
* Method to get the brainkey fron an input of bytes
*
* @param input Array of bytes of the file to be processed
* @param password the pin code
* @return the brainkey file, or null if the file or the password are incorrect
* @return the brainkey file, or null if the file or the password are
* incorrect
*/
public static String getBrainkeyFromByte(byte[] input, String password){
public static String getBrainkeyFromByte(byte[] input, String password) {
//Creates cypher AES with password
//Uncrypt
return null;
}
/**
* Method to generate the file form a brainkey
*
* @param BrainKey The input brainkey
* @param password The pin code
* @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) {
// Cypher AES password
// Get random public key address
// Cypher random public key with aespassword
// Cypher key ciphered key and aespassword
// Cypher brainkey
// Store cypher brainkey and cyher public + password
//LZMA compress
//Generate another public key
//Cypher public key with password
// result Cypher compressed message
return null;
}
public static byte[] compressDataLZMA(byte[] inputBytes) {
LZMAOutputStream out = null;
try {
ByteArrayInputStream input = new ByteArrayInputStream(inputBytes);
ByteArrayOutputStream output = new ByteArrayOutputStream(2048);
LZMA2Options options = new LZMA2Options();
out = new LZMAOutputStream(output, options,-1);
byte[] buf = new byte[inputBytes.length];
int size;
while ((size = input.read(buf)) != -1) {
out.write(buf, 0, size);
}
out.finish();
return output.toByteArray();
} catch (IOException ex) {
Logger.getLogger(FileBin.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
out.close();
} catch (IOException ex) {
Logger.getLogger(FileBin.class.getName()).log(Level.SEVERE, null, ex);
}
}
return null;
}
public static byte[] decompressDataLZMA(byte[] inputBytes) {
LZMAInputStream in = null;
try {
ByteArrayInputStream input = new ByteArrayInputStream(inputBytes);
ByteArrayOutputStream output = new ByteArrayOutputStream(2048);
in = new LZMAInputStream(input);
int size;
while ((size = in.read()) != -1) {
output.write(size);
}
in.close();
return output.toByteArray();
} catch (IOException ex) {
Logger.getLogger(FileBin.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
in.close();
} catch (IOException ex) {
Logger.getLogger(FileBin.class.getName()).log(Level.SEVERE, null, ex);
}
}
return null;
}
}