CipherCodecFactory implements CodecFactory { @Override public Codec createCodec(String clusterId) throws SQLException { String type = getProperty(clusterId, Property.KEYSTORE_TYPE); File file = new File(getProperty(clusterId, Property.KEYSTORE_FILE)); String password = getProperty(clusterId, Property.KEYSTORE_PASSWORD); String keyAlias = getProperty(clusterId, Property.KEY_ALIAS); String keyPassword = getProperty(clusterId, Property.KEY_PASSWORD); try { KeyStore store = KeyStore.getInstance(type); try (InputStream input = new FileInputStream(file)) { store.load(input, (password != null) ? password.toCharArray() : null); } return new CipherCodec(store.getKey(keyAlias, (keyPassword != null) ? keyPassword.toCharArray() : null)); } catch (GeneralSecurityException e) { throw new SQLException(e); } catch (IOException e) { throw new SQLException(e); } }  @Override String getId(); @Override Codec createCodec(String clusterId); static void main(String... args); static final String DEFAULT_KEYSTORE_FILE; static final String DEFAULT_KEY_ALIAS; }
@Test public void test() throws SQLException { Codec codec = new CipherCodecFactory().createCodec("cluster"); Assert.assertTrue(codec instanceof CipherCodec); Assert.assertEquals(this.key, ((CipherCodec) codec).getKey()); }