// Path: Susurrus/app/src/main/java/rocks/susurrus/susurrus/models/EncryptionModel.java
// public class EncryptionModel implements Serializable {
// 
//     /**
//      * Data
//      */
//     private SealedObject sealedObject;
//     private byte[] wrappedKey;
// 
//     public EncryptionModel(SealedObject _sealedObject, byte[] _wrappedKey) {
//         this.sealedObject = _sealedObject;
//         this.wrappedKey = _wrappedKey;
//     }
// 
//     public SealedObject getSealedObject() {
//         return this.sealedObject;
//     }
//     public byte[] getWrappedKey() {
//         return this.wrappedKey;
//     }
// 
// }


import android.util.Base64;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SealedObject;
import javax.crypto.SecretKey;
import rocks.susurrus.susurrus.models.EncryptionModel;
    public static PrivateKey privateStringToKey(String keyString) {
        // convert back to bytes and construct an PKCS8EncodedKeySpec from it
        byte[] keyBytes = Base64.decode(keyString, Base64.DEFAULT);
        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);

        // obtain the publicKey
        PrivateKey privateKey = null;
        try {
            KeyFactory generator = KeyFactory.getInstance(CRYPTO_ALGO);
            privateKey = generator.generatePrivate(keySpec);
        } catch(NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch(InvalidKeySpecException e) {
            e.printStackTrace();
        }

        return privateKey;
    }

    /**
     * Encrypts an unencrypted serializable Object with AES.
     *
     * At first an AES-Session-Key is generated for encrypting the handed SealedObject. The AES-
     * Session-Key is wrapped with the user's publicKey. The wrapped-key can be used to decrypt
     * the SealedObject later.
     *
     * @param _unencryptedObj Serializable object.
     * @param _publicKey The user's publicKey.
     * @return An EncryptionModel with SealedObject and wrapped-Key.
     */
// Path: Susurrus/app/src/main/java/rocks/susurrus/susurrus/models/EncryptionModel.java
// public class EncryptionModel implements Serializable {
// 
//     /**
//      * Data
//      */
//     private SealedObject sealedObject;
//     private byte[] wrappedKey;
// 
//     public EncryptionModel(SealedObject _sealedObject, byte[] _wrappedKey) {
//         this.sealedObject = _sealedObject;
//         this.wrappedKey = _wrappedKey;
//     }
// 
//     public SealedObject getSealedObject() {
//         return this.sealedObject;
//     }
//     public byte[] getWrappedKey() {
//         return this.wrappedKey;
//     }
// 
// }


// Path: Susurrus/app/src/main/java/rocks/susurrus/susurrus/utils/Crypto.java
import android.util.Base64;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SealedObject;
import javax.crypto.SecretKey;
import rocks.susurrus.susurrus.models.EncryptionModel;

    public static PrivateKey privateStringToKey(String keyString) {
        // convert back to bytes and construct an PKCS8EncodedKeySpec from it
        byte[] keyBytes = Base64.decode(keyString, Base64.DEFAULT);
        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);

        // obtain the publicKey
        PrivateKey privateKey = null;
        try {
            KeyFactory generator = KeyFactory.getInstance(CRYPTO_ALGO);
            privateKey = generator.generatePrivate(keySpec);
        } catch(NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch(InvalidKeySpecException e) {
            e.printStackTrace();
        }

        return privateKey;
    }

    /**
     * Encrypts an unencrypted serializable Object with AES.
     *
     * At first an AES-Session-Key is generated for encrypting the handed SealedObject. The AES-
     * Session-Key is wrapped with the user's publicKey. The wrapped-key can be used to decrypt
     * the SealedObject later.
     *
     * @param _unencryptedObj Serializable object.
     * @param _publicKey The user's publicKey.
     * @return An EncryptionModel with SealedObject and wrapped-Key.
     */
    public static EncryptionModel encryptBytes(Serializable _unencryptedObj,