package com.decentralizeddatabase.reno;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;

public class CryptoBlock {

    private final Cipher cipher;

    public CryptoBlock() throws NoSuchPaddingException, NoSuchAlgorithmException {
        this.cipher = Cipher.getInstance("AES");
    }

    /**
     *  Inputs: String (data block), String (16 byte secret key)
     *  Outputs: byte[] (encrypted data block)
     */
    public byte[] encrypt(final byte[] block, final String key) throws NoSuchPaddingException, 
							   NoSuchAlgorithmException, 
							   InvalidKeyException, 
							   BadPaddingException, 
							   IllegalBlockSizeException {
        final Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
        cipher.init(Cipher.ENCRYPT_MODE, aesKey);
        final byte[] encrypted = cipher.doFinal(block);
        return encrypted;
    }

    /**
     *   Inputs: byte[] (encrypted data block), String (16 byte secret key)
     *   Outputs: String (decrypted data block)
     */
    public String decrypt(final byte[] block, final String key) throws InvalidKeyException, 
							   BadPaddingException, 
							   IllegalBlockSizeException {
        Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
        cipher.init(Cipher.DECRYPT_MODE, aesKey);
        String decrypted = new String(cipher.doFinal(block));
        return decrypted;
    }
}

@@ -575,22 +575,22 @@
 Inputs: 
-String
+byte%5B%5D
  (data b
@@ -1224,22 +1224,22 @@
 utputs: 
-String
+byte%5B%5D
  (decryp
@@ -1273,22 +1273,22 @@
  public 
-String
+byte%5B%5D
  decrypt
@@ -1433,16 +1433,22 @@
         
+final 
 Key aesK
@@ -1552,22 +1552,28 @@
         
-String
+final byte%5B%5D
  decrypt
@@ -1581,19 +1581,8 @@
 d = 
-new String(
 ciph
@@ -1598,17 +1598,16 @@
 l(block)
-)
 ;%0A      

Change CryptoBlock.decrypt to use byte array