/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nz.co.lolnet.mercury.util.JamesPlayerGround;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.util.HashMap;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Base64;


public class JamesPlayGround {

    static HashMap<String, String> keys = new HashMap<>();
    static String initVector = "jeXtEsnJreZ4EA6F"; // 16 bytes IV

    public static String encrypt(String key, String value) {
        try {
            IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
            SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");

            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
            cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);

            byte[] encrypted = cipher.doFinal(value.getBytes());

            return Base64.encodeBase64String(encrypted);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return null;
    }

    public static String decrypt(String key, String encrypted) {
        try {
            IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
            SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");

            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);

            byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));

            return new String(original);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return null;
    }

    public static void main(String[] args) {
        String key = "GdfxtHw9ce2SjHEN"; // 128 bit key
        String key2 = "mEbvGDDmYKMka4LAb6eZTZeJ";
        keys.put("James", key);
        keys.put("lx", key2);
        String encrypt = "hh1iTa/bZbUNTX4c1MA7ZA==";
        for (String owner : keys.keySet()) {
            boolean correctKey = false;
            String trykey = keys.get(owner);
            try {
                
            } catch (Exception e) {
            }
        }
        
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("hello",true);
        String input = jsonObject.toString();
    
        String decrypt = decrypt(key2, encrypt);


        System.out.println(decrypt(key, encrypt(key, "Hello World")));
        
        JsonParser parser = new JsonParser();
        System.out.println(jsonObject.toString());
        boolean output = jsonObject.get("hello").getAsBoolean();
        System.out.println(output);
    }
}

@@ -3,187 +3,598 @@
 %0A * 
-To change this license header, choose License Headers in Project Properties.%0A * To change this template file, choose Tools %7C Templates%0A * and open the template in the editor
+Copyright 2017 lolnet.co.nz%0A * %0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * %0A * http://www.apache.org/licenses/LICENSE-2.0%0A * %0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License
 .%0A */%0A
+%0A
 pack
@@ -654,69 +654,24 @@
 ort 
-com.google.gson.JsonObject;%0Aimport com.google.gson.JsonParser
+java.util.Base64
 ;%0Aim
@@ -694,16 +694,17 @@
 ashMap;%0A
+%0A
 import j
@@ -817,46 +817,69 @@
 ort 
-org.apache.commons.codec.binary.Base64
+com.google.gson.JsonObject;%0Aimport com.google.gson.JsonParser
 ;%0A%0A%0A
@@ -1511,20 +1511,29 @@
 e64.
-e
+getE
 ncode
-Base64
+r().encodeTo
 Stri
@@ -2092,20 +2092,27 @@
 e64.
+getDecoder().
 decode
-Base64
 (enc

Use Java8 Base64