@Test public void testGetInputTransform() throws Exception { Map<String, String> objectMetadata = new HashMap<String, String>(); objectMetadata.put("x-emc-enc-object-key", "iyuQuDL9qsfZk2XqnRihfw8ejr+OcrsflXvYD1I5o/Bw+wZPkY4Fm6py8ng25K/iw6kO0zbqq5v5Ywkng0pgrUdHLyR6Aq/dD0vKTK46E6sHZKknlM7NSixR8qaieBwwc2QnhOzyFPIVWSgwo9TqhlPRlOjftRLwU6Nt056BGt5Lhrqn3DeQpTrZW8LDjcpTC1UZtVXe3v9pXB4JEz8M4iFjnFprHykmixlR35RWOw4tIVEbsbcXZwt9RhVsDHj8qnkH66S88y4IOuuU4JJeFMywFXLdDs+MlUrYrA/MvfZNs34WKLYcFICKuLoHoGZ/gReJPbKy64lhSM8gTtYf/Q=="); objectMetadata.put("x-emc-enc-key-id", "e3a69d422e6d9008e3cdfcbea674ccd9ab4758c3"); objectMetadata.put("x-emc-enc-unencrypted-size", "2516125"); objectMetadata.put("x-emc-enc-unencrypted-sha1", "027e997e6b1dfc97b93eb28dc9a6804096d85873"); objectMetadata.put("x-emc-enc-metadata-signature", "F5IG2SC20oFpjLCc+5aETIy25tjUSodNlpmkae/1g91gkCYtP6NG6aLMQLHwyu789LmSegPQ/flUwcqdDE8nCI9Y2SuVbQIE5wvyB7RXRNqDIBKOan4xiOS/G5BwzzPFs6uL3I0b5Ya/VrJYhnDiRMAC+6L5kDbEVesHkx77qqCxku/SSMzCJ2K7kX/MYKfJdNQgXsFMAZs1PEcJpW8viQVTEYR8YR7bx37y4/lIHBotmC7HtB0RWAIGDFcHrnASyqpyHCYnwYjiPqItWaZy7WxRVM+qkH7IMtJT2XCuuI6VFmNzu57LN8p5ROBKO4l0hTgfgHMOUbpmQwuanb6p9Q=="); objectMetadata.put("x-emc-iv", "OCoTA8kO0A+ZKkoZKa7VIQ=="); objectMetadata.put("name1", "value1"); objectMetadata.put("name2", "value2"); InputStream encryptedObject = this.getClass().getClassLoader() .getResourceAsStream("encrypted.txt.keystore.aes128"); KeyStoreEncryptionFactory factory = new KeyStoreEncryptionFactory(keystore, keyAlias, keystorePassword.toCharArray(), provider); 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."); } String masterKeyAlias = idToAliasMap.get(masterKeyId); if(masterKeyAlias == null) { throw new TransformException("Could not find master key for ID " + masterKeyId); } KeyPair asymmetricKey = getKeyPair(masterKeyAlias); return new BasicEncryptionInputTransform(transformTuple[1], streamToDecode, metadata, asymmetricKey, provider); }
KeyStoreEncryptionFactory 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."); } String masterKeyAlias = idToAliasMap.get(masterKeyId); if(masterKeyAlias == null) { throw new TransformException("Could not find master key for ID " + masterKeyId); } KeyPair asymmetricKey = getKeyPair(masterKeyAlias); return new BasicEncryptionInputTransform(transformTuple[1], streamToDecode, metadata, asymmetricKey, provider); } }
KeyStoreEncryptionFactory 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."); } String masterKeyAlias = idToAliasMap.get(masterKeyId); if(masterKeyAlias == null) { throw new TransformException("Could not find master key for ID " + masterKeyId); } KeyPair asymmetricKey = getKeyPair(masterKeyAlias); return new BasicEncryptionInputTransform(transformTuple[1], streamToDecode, metadata, asymmetricKey, provider); } KeyStoreEncryptionFactory(KeyStore keyStore,
            String masterEncryptionKeyAlias, 
            char[] keyStorePassword);  KeyStoreEncryptionFactory(KeyStore keyStore,
            String masterEncryptionKeyAlias, char[] masterKeyPassword, Provider provider); }
KeyStoreEncryptionFactory 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."); } String masterKeyAlias = idToAliasMap.get(masterKeyId); if(masterKeyAlias == null) { throw new TransformException("Could not find master key for ID " + masterKeyId); } KeyPair asymmetricKey = getKeyPair(masterKeyAlias); return new BasicEncryptionInputTransform(transformTuple[1], streamToDecode, metadata, asymmetricKey, provider); } KeyStoreEncryptionFactory(KeyStore keyStore,
            String masterEncryptionKeyAlias, 
            char[] keyStorePassword);  KeyStoreEncryptionFactory(KeyStore keyStore,
            String masterEncryptionKeyAlias, char[] masterKeyPassword, Provider provider); @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); String getMasterEncryptionKeyAlias(); void setMasterEncryptionKeyAlias(String alias); }
KeyStoreEncryptionFactory 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."); } String masterKeyAlias = idToAliasMap.get(masterKeyId); if(masterKeyAlias == null) { throw new TransformException("Could not find master key for ID " + masterKeyId); } KeyPair asymmetricKey = getKeyPair(masterKeyAlias); return new BasicEncryptionInputTransform(transformTuple[1], streamToDecode, metadata, asymmetricKey, provider); } KeyStoreEncryptionFactory(KeyStore keyStore,
            String masterEncryptionKeyAlias, 
            char[] keyStorePassword);  KeyStoreEncryptionFactory(KeyStore keyStore,
            String masterEncryptionKeyAlias, char[] masterKeyPassword, Provider provider); @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); String getMasterEncryptionKeyAlias(); void setMasterEncryptionKeyAlias(String alias);  }