@Test public void testGetInputTransform() throws Exception { Map<String, String> objectMetadata = new HashMap<String, String>(); objectMetadata.put("x-emc-enc-object-key", "holbhxpDq92g0dPRuqmtAt23KaNSm3JjKULdzadKdJyn3SINDSbaHnjmDU/Aa5pNSmq8ij+RWdkBlsrk9g6m/tjQm1gMPbeW+IhWJhInL0Mvsa+olZ+cLkztnKz/yHQ6vj9R0m8OboATweV1TTkRx9RFrr2nEBY7jKHNxd8JOJ/1I3gteuhsLKKE9oF2uS0UTVnCTZ3S6tf0W4P9D0PTW9LXQaA3KkFD+4tEbqZfC4ov88CLRAL72YC6KCF1LDZdqGzvqKf2j+92xIiy99+5LatVJPUebVucM8Equ6lAcETjNEsIwLPSNz2P9/saYI8XdLyZQDsOMg/32BbtVCVs7g=="); objectMetadata.put("x-emc-enc-key-id", "000317457b5645b7b5c4daf4cf6780c05438effd"); objectMetadata.put("x-emc-enc-unencrypted-size", "2516125"); objectMetadata.put("x-emc-enc-unencrypted-sha1", "027e997e6b1dfc97b93eb28dc9a6804096d85873"); objectMetadata.put("x-emc-enc-metadata-signature", "G98fTE0w8HzdzbqXv5x5AKl2/MudwrEIJ3nZciI1H9HQKg+i3Jmvi+/miEOeyMv8+lOVDj6CiBUMBpUsqrx46NODC+0MiA3L2JotW2DUJqfvfaTKtgbbFdSUYHshDDw3zZXcULX/flk5vjTYTICBSjedn9tg+VTA24ivk4IPexmPR7BKN+UmRZv6nPuvV1soGWg69K+5qv47lQf2rC4yO7FUXRJA10+nES1/8UmB3NylCwgI/a7UKu00o8kYABqgzVNbWgB4GjCqOtNcWJGSz8Xku3nWySetFLVs0wcwioZ3KyHIf+6p4XzbHx1ie4t9fhZuAYoOTPqDTu0o0QB/pg=="); objectMetadata.put("x-emc-iv", "omQ2kgZauWkK58/m+Eichg=="); objectMetadata.put("name1", "value1"); objectMetadata.put("name2", "value2"); InputStream encryptedObject = this.getClass().getClassLoader() .getResourceAsStream("encrypted.txt.aes128"); BasicEncryptionTransformFactory factory = new BasicEncryptionTransformFactory(); factory.setCryptoProvider(provider); factory.setMasterEncryptionKey(masterKey); InputTransform inTransform = factory.getInputTransform("ENC:AES/CBC/PKCS5Padding", encryptedObject, objectMetadata); InputStream inStream = inTransform.getDecodedInputStream(); byte[] buffer = new byte[4096]; int c = 0; ByteArrayOutputStream decryptedData = new ByteArrayOutputStream(); while ((c = inStream.read(buffer)) != -1) { decryptedData.write(buffer, 0, c); } InputStream originalStream = this.getClass().getClassLoader() .getResourceAsStream("uncompressed.txt"); ByteArrayOutputStream classByteStream = new ByteArrayOutputStream(); while ((c = originalStream.read(buffer)) != -1) { classByteStream.write(buffer, 0, c); } byte[] originalData = classByteStream.toByteArray(); originalStream.close(); assertArrayEquals("Decrypted data incorrect", originalData, decryptedData.toByteArray()); }
@Override public BasicEncryptionInputTransform getInputTransform( String transformConfig, InputStream streamToDecode, Map<String, String> metadata) throws IOException, TransformException { String[] transformTuple = splitTransformConfig(transformConfig); if (transformTuple.length != 2) { throw new TransformException("Invalid transform configuration: " + transformConfig); } if (!TransformConstants.ENCRYPTION_CLASS.equals(transformTuple[0])) { throw new TransformException("Unsupported transform class: " + transformTuple[0]); } String masterKeyId = metadata .get(TransformConstants.META_ENCRYPTION_KEY_ID); if (masterKeyId == null) { throw new TransformException( "Could not decrypt object. No master key ID set on object."); } KeyPair masterKey = masterDecryptionKeys.get(masterKeyId); if (masterKey == null) { throw new TransformException( "Could not decrypt object. No master key with ID " + masterKeyId + " found"); } return new BasicEncryptionInputTransform(transformTuple[1], streamToDecode, metadata, masterKey, provider); }
BasicEncryptionTransformFactory extends
        EncryptionTransformFactory<BasicEncryptionOutputTransform, BasicEncryptionInputTransform> { @Override public BasicEncryptionInputTransform getInputTransform( String transformConfig, InputStream streamToDecode, Map<String, String> metadata) throws IOException, TransformException { String[] transformTuple = splitTransformConfig(transformConfig); if (transformTuple.length != 2) { throw new TransformException("Invalid transform configuration: " + transformConfig); } if (!TransformConstants.ENCRYPTION_CLASS.equals(transformTuple[0])) { throw new TransformException("Unsupported transform class: " + transformTuple[0]); } String masterKeyId = metadata .get(TransformConstants.META_ENCRYPTION_KEY_ID); if (masterKeyId == null) { throw new TransformException( "Could not decrypt object. No master key ID set on object."); } KeyPair masterKey = masterDecryptionKeys.get(masterKeyId); if (masterKey == null) { throw new TransformException( "Could not decrypt object. No master key with ID " + masterKeyId + " found"); } return new BasicEncryptionInputTransform(transformTuple[1], streamToDecode, metadata, masterKey, provider); } }
BasicEncryptionTransformFactory extends
        EncryptionTransformFactory<BasicEncryptionOutputTransform, BasicEncryptionInputTransform> { @Override public BasicEncryptionInputTransform getInputTransform( String transformConfig, InputStream streamToDecode, Map<String, String> metadata) throws IOException, TransformException { String[] transformTuple = splitTransformConfig(transformConfig); if (transformTuple.length != 2) { throw new TransformException("Invalid transform configuration: " + transformConfig); } if (!TransformConstants.ENCRYPTION_CLASS.equals(transformTuple[0])) { throw new TransformException("Unsupported transform class: " + transformTuple[0]); } String masterKeyId = metadata .get(TransformConstants.META_ENCRYPTION_KEY_ID); if (masterKeyId == null) { throw new TransformException( "Could not decrypt object. No master key ID set on object."); } KeyPair masterKey = masterDecryptionKeys.get(masterKeyId); if (masterKey == null) { throw new TransformException( "Could not decrypt object. No master key with ID " + masterKeyId + " found"); } return new BasicEncryptionInputTransform(transformTuple[1], streamToDecode, metadata, masterKey, provider); } BasicEncryptionTransformFactory();  BasicEncryptionTransformFactory(KeyPair masterEncryptionKey, 
            Set<KeyPair> masterDecryptionKeys);  BasicEncryptionTransformFactory(KeyPair masterEncryptionKey, 
            Set<KeyPair> masterDecryptionKeys, Provider provider); }
BasicEncryptionTransformFactory extends
        EncryptionTransformFactory<BasicEncryptionOutputTransform, BasicEncryptionInputTransform> { @Override public BasicEncryptionInputTransform getInputTransform( String transformConfig, InputStream streamToDecode, Map<String, String> metadata) throws IOException, TransformException { String[] transformTuple = splitTransformConfig(transformConfig); if (transformTuple.length != 2) { throw new TransformException("Invalid transform configuration: " + transformConfig); } if (!TransformConstants.ENCRYPTION_CLASS.equals(transformTuple[0])) { throw new TransformException("Unsupported transform class: " + transformTuple[0]); } String masterKeyId = metadata .get(TransformConstants.META_ENCRYPTION_KEY_ID); if (masterKeyId == null) { throw new TransformException( "Could not decrypt object. No master key ID set on object."); } KeyPair masterKey = masterDecryptionKeys.get(masterKeyId); if (masterKey == null) { throw new TransformException( "Could not decrypt object. No master key with ID " + masterKeyId + " found"); } return new BasicEncryptionInputTransform(transformTuple[1], streamToDecode, metadata, masterKey, provider); } BasicEncryptionTransformFactory();  BasicEncryptionTransformFactory(KeyPair masterEncryptionKey, 
            Set<KeyPair> masterDecryptionKeys);  BasicEncryptionTransformFactory(KeyPair masterEncryptionKey, 
            Set<KeyPair> masterDecryptionKeys, Provider provider); void setMasterEncryptionKey(KeyPair pair); void addMasterDecryptionKey(KeyPair pair); @Override Map<String, String> rekey(Map<String, String> metadata); @Override BasicEncryptionOutputTransform getOutputTransform(
            OutputStream streamToEncodeTo, Map<String, String> metadataToEncode); @Override BasicEncryptionOutputTransform getOutputTransform(
            InputStream streamToEncode, Map<String, String> metadataToEncode); @Override BasicEncryptionInputTransform getInputTransform(
            String transformConfig, InputStream streamToDecode,
            Map<String, String> metadata); }
BasicEncryptionTransformFactory extends
        EncryptionTransformFactory<BasicEncryptionOutputTransform, BasicEncryptionInputTransform> { @Override public BasicEncryptionInputTransform getInputTransform( String transformConfig, InputStream streamToDecode, Map<String, String> metadata) throws IOException, TransformException { String[] transformTuple = splitTransformConfig(transformConfig); if (transformTuple.length != 2) { throw new TransformException("Invalid transform configuration: " + transformConfig); } if (!TransformConstants.ENCRYPTION_CLASS.equals(transformTuple[0])) { throw new TransformException("Unsupported transform class: " + transformTuple[0]); } String masterKeyId = metadata .get(TransformConstants.META_ENCRYPTION_KEY_ID); if (masterKeyId == null) { throw new TransformException( "Could not decrypt object. No master key ID set on object."); } KeyPair masterKey = masterDecryptionKeys.get(masterKeyId); if (masterKey == null) { throw new TransformException( "Could not decrypt object. No master key with ID " + masterKeyId + " found"); } return new BasicEncryptionInputTransform(transformTuple[1], streamToDecode, metadata, masterKey, provider); } BasicEncryptionTransformFactory();  BasicEncryptionTransformFactory(KeyPair masterEncryptionKey, 
            Set<KeyPair> masterDecryptionKeys);  BasicEncryptionTransformFactory(KeyPair masterEncryptionKey, 
            Set<KeyPair> masterDecryptionKeys, Provider provider); void setMasterEncryptionKey(KeyPair pair); void addMasterDecryptionKey(KeyPair pair); @Override Map<String, String> rekey(Map<String, String> metadata); @Override BasicEncryptionOutputTransform getOutputTransform(
            OutputStream streamToEncodeTo, Map<String, String> metadataToEncode); @Override BasicEncryptionOutputTransform getOutputTransform(
            InputStream streamToEncode, Map<String, String> metadataToEncode); @Override BasicEncryptionInputTransform getInputTransform(
            String transformConfig, InputStream streamToDecode,
            Map<String, String> metadata); public KeyPair masterEncryptionKey; }