// Path: core/src/main/java/io/keen/client/java/exceptions/ScopedKeyException.java
// public class ScopedKeyException extends KeenException {
//     private static final long serialVersionUID = -8250886829624436391L;
// 
//     public ScopedKeyException() {
//         super();
//     }
// 
//     public ScopedKeyException(Throwable cause) {
//         super(cause);
//     }
// 
//     public ScopedKeyException(String message) {
//         super(message);
//     }
// 
//     public ScopedKeyException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }


import java.io.StringReader;
import java.io.StringWriter;
import java.security.AlgorithmParameters;
import java.util.HashMap;
import java.util.Map;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import io.keen.client.java.exceptions.ScopedKeyException;
package io.keen.client.java;




/**
 * ScopedKeys is a utility class for dealing with Keen Scoped Keys. You'll probably only ever need the
 * encrypt method. However, for completeness, there's also a decrypt method.
 * <p>
 * Example usage:
 * </p>
 * <pre>
 *     {@code
 *     String apiKey = "YOUR_API_KEY_HERE";
 *
 *     //Filters to apply to the key
 *     Map<String, Object> filter = new HashMap<String, Object>();
 *     List<Map<String, Object>> filters = new ArrayList<Map<String, Object>>();
 *
 *     //Create and add a filter
 *     filter.put("property_name", "user_id");
 *     filter.put("operator", "eq");
 *     filter.put("property_value", "123");
 *
 *     filters.add(filter);
 *
 *     // create the options we'll use
 *     Map<String, Object> options = new HashMap<String, Object>();
 *     options.put("allowed_operations", Arrays.asList("write"));
 *     options.put("filters", filters);
 *
 *     // do the encryption
 *     String scopedKey = ScopedKeys.encrypt(apiKey, options);
 *     }
 * </pre>
 *
 * @author dkador
 * @since 1.0.3
 */
public class ScopedKeys {

    private static final int BLOCK_SIZE = 32;

    // TODO: Review exceptions from this class.

    /**
     * Encrypts the given options with a Keen API Key and creates a Scoped Key.
     *
     * @param apiKey  Your Keen API Key.
     * @param options The options you want to encrypt.
     * @return A Keen Scoped Key.
     * @throws ScopedKeyException an error occurred while attempting to encrypt a Scoped Key.
     */
    public static String encrypt(String apiKey, Map<String, Object> options)
// Path: core/src/main/java/io/keen/client/java/exceptions/ScopedKeyException.java
// public class ScopedKeyException extends KeenException {
//     private static final long serialVersionUID = -8250886829624436391L;
// 
//     public ScopedKeyException() {
//         super();
//     }
// 
//     public ScopedKeyException(Throwable cause) {
//         super(cause);
//     }
// 
//     public ScopedKeyException(String message) {
//         super(message);
//     }
// 
//     public ScopedKeyException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }


// Path: core/src/main/java/io/keen/client/java/ScopedKeys.java
import java.io.StringReader;
import java.io.StringWriter;
import java.security.AlgorithmParameters;
import java.util.HashMap;
import java.util.Map;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import io.keen.client.java.exceptions.ScopedKeyException;

package io.keen.client.java;




/**
 * ScopedKeys is a utility class for dealing with Keen Scoped Keys. You'll probably only ever need the
 * encrypt method. However, for completeness, there's also a decrypt method.
 * <p>
 * Example usage:
 * </p>
 * <pre>
 *     {@code
 *     String apiKey = "YOUR_API_KEY_HERE";
 *
 *     //Filters to apply to the key
 *     Map<String, Object> filter = new HashMap<String, Object>();
 *     List<Map<String, Object>> filters = new ArrayList<Map<String, Object>>();
 *
 *     //Create and add a filter
 *     filter.put("property_name", "user_id");
 *     filter.put("operator", "eq");
 *     filter.put("property_value", "123");
 *
 *     filters.add(filter);
 *
 *     // create the options we'll use
 *     Map<String, Object> options = new HashMap<String, Object>();
 *     options.put("allowed_operations", Arrays.asList("write"));
 *     options.put("filters", filters);
 *
 *     // do the encryption
 *     String scopedKey = ScopedKeys.encrypt(apiKey, options);
 *     }
 * </pre>
 *
 * @author dkador
 * @since 1.0.3
 */
public class ScopedKeys {

    private static final int BLOCK_SIZE = 32;

    // TODO: Review exceptions from this class.

    /**
     * Encrypts the given options with a Keen API Key and creates a Scoped Key.
     *
     * @param apiKey  Your Keen API Key.
     * @param options The options you want to encrypt.
     * @return A Keen Scoped Key.
     * @throws ScopedKeyException an error occurred while attempting to encrypt a Scoped Key.
     */
    public static String encrypt(String apiKey, Map<String, Object> options)
            throws ScopedKeyException {