Package com.amazonaws.util.json

Examples of com.amazonaws.util.json.JSONObject


      while ((line = reader.readLine()) != null) {
        buffer.append(line);
      }

      JSONObject jsonObject = new JSONObject(buffer.toString());
      PrintWriter out = response.getWriter();

      String action = jsonObject.getString("action");
      log("action: " + action);
      JSONObject requestObject = jsonObject.getJSONObject("request");
      log("requestObject: " + requestObject);

      if (action.equalsIgnoreCase("put-point")) {
        putPoint(requestObject, out);
      } else if (action.equalsIgnoreCase("get-point")) {
View Full Code Here


     *      preferred provider from Security.getProviders().
     * @return
     *      A non-null instruction object containing encryption information
     */
    public static EncryptionInstruction buildInstructionFromInstructionFile(S3Object instructionFile, EncryptionMaterialsProvider materialsProvider, Provider cryptoProvider) {
        JSONObject instructionJSON = parseJSONInstruction(instructionFile);
        try {
            // Get fields from instruction object
            String encryptedSymmetricKeyB64 = instructionJSON.getString(Headers.CRYPTO_KEY);
            String ivB64 = instructionJSON.getString(Headers.CRYPTO_IV);
            String materialsDescriptionString = instructionJSON.tryGetString(Headers.MATERIALS_DESCRIPTION);
            Map<String, String> materialsDescription = convertJSONToMap(materialsDescriptionString);

            // Decode from Base 64 to standard binary bytes
            byte[] encryptedSymmetricKey = Base64.decode(encryptedSymmetricKeyB64);
            byte[] iv = Base64.decode(ivB64);
View Full Code Here

     *      The instruction object to be stored in S3.
     * @return
     *      A put request to store the specified instruction object in S3.
     */
    public static PutObjectRequest createInstructionPutRequest(PutObjectRequest request, EncryptionInstruction instruction) {
        JSONObject instructionJSON = convertInstructionToJSONObject(instruction);
        byte[] instructionBytes = instructionJSON.toString().getBytes();
        InputStream instructionInputStream = new ByteArrayInputStream(instructionBytes);

        ObjectMetadata metadata = request.getMetadata();

        // Set the content-length of the upload
View Full Code Here

        return request;
    }

    public static PutObjectRequest createInstructionPutRequest(String bucketName, String key, EncryptionInstruction instruction) {
        JSONObject instructionJSON = convertInstructionToJSONObject(instruction);
        byte[] instructionBytes = instructionJSON.toString().getBytes();
        InputStream instructionInputStream = new ByteArrayInputStream(instructionBytes);

        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength(instructionBytes.length);
        metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, "");
View Full Code Here

    private static Map<String, String> convertJSONToMap(String descriptionJSONString) {
        if (descriptionJSONString == null) {
            return null;
        }
        try {
            JSONObject descriptionJSON = new JSONObject(descriptionJSONString);
            Iterator<String> keysIterator = descriptionJSON.keys();
            Map<String, String> materialsDescription = new HashMap<String, String>();
            while(keysIterator.hasNext()) {
                String key = keysIterator.next();
                materialsDescription.put(key, descriptionJSON.getString(key));
            }
            return materialsDescription;
        } catch (JSONException e) {
            throw new AmazonClientException("Unable to parse encryption materials description from metadata :" + e.getMessage());
        }
View Full Code Here

        // Put the cipher initialization vector (IV) into the object metadata
        metadata.addUserMetadata(Headers.CRYPTO_IV,
                Base64.encodeAsString(symmetricCipher.getIV()));

        // Put the materials description into the object metadata as JSON
        JSONObject descriptionJSON = new JSONObject(materialsDescription);
        metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION, descriptionJSON.toString());
    }
View Full Code Here

    /**
     * Returns a JSONObject representation of the instruction object.
     */
    private static JSONObject convertInstructionToJSONObject(EncryptionInstruction instruction) {
        JSONObject instructionJSON = new JSONObject();
        try {
            JSONObject materialsDescriptionJSON = new JSONObject(
                    instruction.getMaterialsDescription());
            instructionJSON.put(Headers.MATERIALS_DESCRIPTION,
                    materialsDescriptionJSON.toString());
            instructionJSON.put(Headers.CRYPTO_KEY,
                Base64.encodeAsString(instruction.getEncryptedSymmetricKey()));
            byte[] iv = instruction.getSymmetricCipher().getIV();
            instructionJSON.put(Headers.CRYPTO_IV, Base64.encodeAsString(iv));
        } catch (JSONException e) {} // Keys are never null, so JSONException will never be thrown.
View Full Code Here

     * Parses instruction data retrieved from S3 and returns a JSONObject representing the instruction
     */
    private static JSONObject parseJSONInstruction(S3Object instructionObject) {
        try {
            String instructionString = convertStreamToString(instructionObject.getObjectContent());
            return new JSONObject(instructionString);
        } catch (Exception e) {
            throw new AmazonClientException("Error parsing JSON instruction file: " + e.getMessage());
        }
    }
View Full Code Here

     *      preferred provider from Security.getProviders().
     * @return
     *      A non-null instruction object containing encryption information
     */
    public static EncryptionInstruction buildInstructionFromInstructionFile(S3Object instructionFile, EncryptionMaterials materials, Provider cryptoProvider) {
        JSONObject instructionJSON = parseJSONInstruction(instructionFile);
        try {
            // Get fields from instruction object
            byte[] encryptedSymmetricKeyBytes = instructionJSON.getString(Headers.CRYPTO_KEY).getBytes();
            byte[] initVectorBytes = instructionJSON.getString(Headers.CRYPTO_IV).getBytes();
            String materialsDescriptionString = instructionJSON.getString(Headers.MATERIALS_DESCRIPTION);
            Map<String, String> materialsDescription = convertJSONToMap(materialsDescriptionString);

            // Decode from Base 64 to standard binary bytes
            encryptedSymmetricKeyBytes = Base64.decodeBase64(encryptedSymmetricKeyBytes);
            initVectorBytes = Base64.decodeBase64(initVectorBytes);
View Full Code Here

     *      The instruction object to be stored in S3.
     * @return
     *      A put request to store the specified instruction object in S3.
     */
    public static PutObjectRequest createInstructionPutRequest(PutObjectRequest request, EncryptionInstruction instruction) {
        JSONObject instructionJSON = convertInstructionToJSONObject(instruction);
        byte[] instructionBytes = instructionJSON.toString().getBytes();
        InputStream instructionInputStream = new ByteArrayInputStream(instructionBytes);

        ObjectMetadata metadata = request.getMetadata();

        // Set the content-length of the upload
View Full Code Here

TOP

Related Classes of com.amazonaws.util.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.