code: public static String encrypt(KeenClient client, String apiKey, Map<String, Object> options)
              throws ScopedKeyException {
          try {
              // if the user doesn't give an options, just use an empty one
              if (options == null) {
                  options = new HashMap<String, Object>();
              }
  
              // convert the api key from hex string to byte array
              final byte[] apiKeyBytes = KeenUtils.hexStringToByteArray(apiKey);
  
              // json encode the options
              StringWriter writer = new StringWriter();
              client.getJsonHandler().writeJson(writer, options);
              final String jsonOptions = writer.toString();
  
              // setup the API key as the secret
              final SecretKey secret = new SecretKeySpec(apiKeyBytes, "AES");
  
              // get the right AES cipher
              final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
              cipher.init(Cipher.ENCRYPT_MODE, secret);
  
              final AlgorithmParameters params = cipher.getParameters();
              // get a random IV for each encryption
              final byte[] iv = params.getParameterSpec(IvParameterSpec.class).getIV();
              // do the actual encryption (this also pads jsonOptions)
              final byte[] cipherText = cipher.doFinal(jsonOptions.getBytes("UTF-8"));
  
              // now return the hexed iv + the hexed cipher text
              return KeenUtils.byteArrayToHexString(iv) + KeenUtils.byteArrayToHexString(cipherText);
          } catch (Exception e) {
              throw new ScopedKeyException("An error occurred while attempting to encrypt a Scoped Key", e);
          }
      }
docs: Encrypts the given options with a Keen API Key and creates a Scoped Key.
  
  @param client  The KeenClient to use for JSON handling.
  @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.