package net.bither.bitherj.crypto;

/**
 * Created by songchenwen on 15/1/4.
 */
public class EncryptedData {
    private byte[] encryptedData;
    private byte[] initialisationVector;
    private byte[] salt;

    private boolean isCompressed;
    private boolean isFromXRandom;

    public EncryptedData(String str){
        //TODO from encrypted string
    }

    public EncryptedData(byte[] dataToEncrypt, CharSequence password){
        this(dataToEncrypt, password, false);
    }

    public EncryptedData(byte[] dataToEncrypt, CharSequence password, boolean isFromXRandom){
        this(dataToEncrypt, password, isFromXRandom, true);
    }

    public EncryptedData(byte[] dataToEncrypt, CharSequence password, boolean isFromXRandom, boolean isCompressed){
        this.isCompressed = isCompressed;
        this.isFromXRandom = isFromXRandom;
        KeyCrypterScrypt crypter = new KeyCrypterScrypt();
        salt = crypter.getSalt();
        EncryptedPrivateKey k = crypter.encrypt(dataToEncrypt, crypter.deriveKey(password));
        encryptedData = k.getEncryptedBytes();
        initialisationVector = k.getInitialisationVector();
    }

    public byte[] decrypt(CharSequence password){
        KeyCrypterScrypt crypter = new KeyCrypterScrypt(salt);
        return crypter.decrypt(new EncryptedPrivateKey(initialisationVector, encryptedData), crypter.deriveKey(password));
    }

    public boolean isCompressed() {
        return isCompressed;
    }

    public boolean isFromXRandom() {
        return isFromXRandom;
    }

    public String toString(){
        //TODO to string
        return null;
    }

}

@@ -208,78 +208,8 @@
 t;%0A%0A
-    private boolean isCompressed;%0A    private boolean isFromXRandom;%0A%0A
     
@@ -242,16 +242,16 @@
 g str)%7B%0A
+
         
@@ -691,94 +691,8 @@
 d)%7B%0A
-        this.isCompressed = isCompressed;%0A        this.isFromXRandom = isFromXRandom;%0A
     
@@ -1100,16 +1100,16 @@
 (salt);%0A
+
         
@@ -1234,154 +1234,8 @@
  %7D%0A%0A
-    public boolean isCompressed() %7B%0A        return isCompressed;%0A    %7D%0A%0A    public boolean isFromXRandom() %7B%0A        return isFromXRandom;%0A    %7D%0A%0A
     

delete compressed and xrandom from encrypted data