@Test public void testCanBuildAes() throws IOException { Map<String, Object> properties = new HashMap<>(); properties.put(EncryptionConfigParser.ENCRYPTION_ALGORITHM_KEY, "aes_rotating"); properties.put(EncryptionConfigParser.ENCRYPTION_KEYSTORE_PATH_KEY, getClass().getResource( "/encryption_provider_test_keystore").toString()); properties.put(EncryptionConfigParser.ENCRYPTION_KEYSTORE_PASSWORD_KEY, "abcd"); StreamCodec c = EncryptionFactory.buildStreamCryptoProvider(properties); Assert.assertNotNull(c); byte[] toEncrypt = "Hello!".getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream cipherOut = new ByteArrayOutputStream(); OutputStream cipherStream = c.encodeOutputStream(cipherOut); cipherStream.write(toEncrypt); cipherStream.close(); Assert.assertTrue(cipherOut.size() > 0, "Expected to be able to write ciphertext!"); }
public StreamCodec buildStreamCryptoProvider(String algorithm, Map<String, Object> parameters) { switch (algorithm) { case EncryptionConfigParser.ENCRYPTION_TYPE_ANY: case "aes_rotating": CredentialStore cs = CredentialStoreFactory.buildCredentialStore(parameters); if (cs == null) { throw new IllegalArgumentException("Failed to build credential store; can't instantiate AES"); } return new RotatingAESCodec(cs); case GPGCodec.TAG: String password = EncryptionConfigParser.getKeystorePassword(parameters); String keystorePathStr = EncryptionConfigParser.getKeystorePath(parameters); String keyName = EncryptionConfigParser.getKeyName(parameters); String cipherName = EncryptionConfigParser.getCipher(parameters); if (keystorePathStr == null) { Preconditions.checkNotNull(password, "Must specify an en/decryption password for GPGCodec!"); return new GPGCodec(password, cipherName); } return new GPGCodec(new Path(keystorePathStr), password, keyName == null ? 0 : Long.parseUnsignedLong(keyName, 16), cipherName); default: log.debug("Do not support encryption type {}", algorithm); return null; } }
GobblinEncryptionProvider implements CredentialStoreProvider, EncryptionProvider { public StreamCodec buildStreamCryptoProvider(String algorithm, Map<String, Object> parameters) { switch (algorithm) { case EncryptionConfigParser.ENCRYPTION_TYPE_ANY: case "aes_rotating": CredentialStore cs = CredentialStoreFactory.buildCredentialStore(parameters); if (cs == null) { throw new IllegalArgumentException("Failed to build credential store; can't instantiate AES"); } return new RotatingAESCodec(cs); case GPGCodec.TAG: String password = EncryptionConfigParser.getKeystorePassword(parameters); String keystorePathStr = EncryptionConfigParser.getKeystorePath(parameters); String keyName = EncryptionConfigParser.getKeyName(parameters); String cipherName = EncryptionConfigParser.getCipher(parameters); if (keystorePathStr == null) { Preconditions.checkNotNull(password, "Must specify an en/decryption password for GPGCodec!"); return new GPGCodec(password, cipherName); } return new GPGCodec(new Path(keystorePathStr), password, keyName == null ? 0 : Long.parseUnsignedLong(keyName, 16), cipherName); default: log.debug("Do not support encryption type {}", algorithm); return null; } } }
GobblinEncryptionProvider implements CredentialStoreProvider, EncryptionProvider { public StreamCodec buildStreamCryptoProvider(String algorithm, Map<String, Object> parameters) { switch (algorithm) { case EncryptionConfigParser.ENCRYPTION_TYPE_ANY: case "aes_rotating": CredentialStore cs = CredentialStoreFactory.buildCredentialStore(parameters); if (cs == null) { throw new IllegalArgumentException("Failed to build credential store; can't instantiate AES"); } return new RotatingAESCodec(cs); case GPGCodec.TAG: String password = EncryptionConfigParser.getKeystorePassword(parameters); String keystorePathStr = EncryptionConfigParser.getKeystorePath(parameters); String keyName = EncryptionConfigParser.getKeyName(parameters); String cipherName = EncryptionConfigParser.getCipher(parameters); if (keystorePathStr == null) { Preconditions.checkNotNull(password, "Must specify an en/decryption password for GPGCodec!"); return new GPGCodec(password, cipherName); } return new GPGCodec(new Path(keystorePathStr), password, keyName == null ? 0 : Long.parseUnsignedLong(keyName, 16), cipherName); default: log.debug("Do not support encryption type {}", algorithm); return null; } } GobblinEncryptionProvider(); }
GobblinEncryptionProvider implements CredentialStoreProvider, EncryptionProvider { public StreamCodec buildStreamCryptoProvider(String algorithm, Map<String, Object> parameters) { switch (algorithm) { case EncryptionConfigParser.ENCRYPTION_TYPE_ANY: case "aes_rotating": CredentialStore cs = CredentialStoreFactory.buildCredentialStore(parameters); if (cs == null) { throw new IllegalArgumentException("Failed to build credential store; can't instantiate AES"); } return new RotatingAESCodec(cs); case GPGCodec.TAG: String password = EncryptionConfigParser.getKeystorePassword(parameters); String keystorePathStr = EncryptionConfigParser.getKeystorePath(parameters); String keyName = EncryptionConfigParser.getKeyName(parameters); String cipherName = EncryptionConfigParser.getCipher(parameters); if (keystorePathStr == null) { Preconditions.checkNotNull(password, "Must specify an en/decryption password for GPGCodec!"); return new GPGCodec(password, cipherName); } return new GPGCodec(new Path(keystorePathStr), password, keyName == null ? 0 : Long.parseUnsignedLong(keyName, 16), cipherName); default: log.debug("Do not support encryption type {}", algorithm); return null; } } GobblinEncryptionProvider(); static Set<String> supportedStreamingAlgorithms(); StreamCodec buildStreamEncryptor(Map<String, Object> parameters); StreamCodec buildStreamCryptoProvider(String algorithm, Map<String, Object> parameters); CredentialStore buildCredentialStore(Map<String, Object> parameters); }
GobblinEncryptionProvider implements CredentialStoreProvider, EncryptionProvider { public StreamCodec buildStreamCryptoProvider(String algorithm, Map<String, Object> parameters) { switch (algorithm) { case EncryptionConfigParser.ENCRYPTION_TYPE_ANY: case "aes_rotating": CredentialStore cs = CredentialStoreFactory.buildCredentialStore(parameters); if (cs == null) { throw new IllegalArgumentException("Failed to build credential store; can't instantiate AES"); } return new RotatingAESCodec(cs); case GPGCodec.TAG: String password = EncryptionConfigParser.getKeystorePassword(parameters); String keystorePathStr = EncryptionConfigParser.getKeystorePath(parameters); String keyName = EncryptionConfigParser.getKeyName(parameters); String cipherName = EncryptionConfigParser.getCipher(parameters); if (keystorePathStr == null) { Preconditions.checkNotNull(password, "Must specify an en/decryption password for GPGCodec!"); return new GPGCodec(password, cipherName); } return new GPGCodec(new Path(keystorePathStr), password, keyName == null ? 0 : Long.parseUnsignedLong(keyName, 16), cipherName); default: log.debug("Do not support encryption type {}", algorithm); return null; } } GobblinEncryptionProvider(); static Set<String> supportedStreamingAlgorithms(); StreamCodec buildStreamEncryptor(Map<String, Object> parameters); StreamCodec buildStreamCryptoProvider(String algorithm, Map<String, Object> parameters); CredentialStore buildCredentialStore(Map<String, Object> parameters);  }