@Test public void testGetCipher() { Map<String, String> properties = new HashMap<>(); properties.put(CryptoConstants.CIPHER_ALGORITHM, "AES"); properties.put(CryptoConstants.CIPHER_MODE, "CBC"); properties.put(CryptoConstants.CIPHER_PADDING, "PKCS5Padding"); DefaultCipherFactory f = new DefaultCipherFactory(properties); Cipher c = f.cipher(); assertNotNull(c); assertEquals("AES/CBC/PKCS5Padding", c.getAlgorithm()); }
@Override public Cipher cipher() { try { return Cipher.getInstance(transformation); } catch (NoSuchAlgorithmException e) { throw new CayenneCryptoException("Error instantiating a cipher - no such algorithm: " + transformation, e); } catch (NoSuchPaddingException e) { throw new CayenneCryptoException("Error instantiating a cipher - no such padding: " + transformation, e); } }
DefaultCipherFactory implements CipherFactory { @Override public Cipher cipher() { try { return Cipher.getInstance(transformation); } catch (NoSuchAlgorithmException e) { throw new CayenneCryptoException("Error instantiating a cipher - no such algorithm: " + transformation, e); } catch (NoSuchPaddingException e) { throw new CayenneCryptoException("Error instantiating a cipher - no such padding: " + transformation, e); } } }
DefaultCipherFactory implements CipherFactory { @Override public Cipher cipher() { try { return Cipher.getInstance(transformation); } catch (NoSuchAlgorithmException e) { throw new CayenneCryptoException("Error instantiating a cipher - no such algorithm: " + transformation, e); } catch (NoSuchPaddingException e) { throw new CayenneCryptoException("Error instantiating a cipher - no such padding: " + transformation, e); } } DefaultCipherFactory(@Inject(CryptoConstants.PROPERTIES_MAP) Map<String, String> properties); }
DefaultCipherFactory implements CipherFactory { @Override public Cipher cipher() { try { return Cipher.getInstance(transformation); } catch (NoSuchAlgorithmException e) { throw new CayenneCryptoException("Error instantiating a cipher - no such algorithm: " + transformation, e); } catch (NoSuchPaddingException e) { throw new CayenneCryptoException("Error instantiating a cipher - no such padding: " + transformation, e); } } DefaultCipherFactory(@Inject(CryptoConstants.PROPERTIES_MAP) Map<String, String> properties); @Override Cipher cipher(); @Override int blockSize(); }
DefaultCipherFactory implements CipherFactory { @Override public Cipher cipher() { try { return Cipher.getInstance(transformation); } catch (NoSuchAlgorithmException e) { throw new CayenneCryptoException("Error instantiating a cipher - no such algorithm: " + transformation, e); } catch (NoSuchPaddingException e) { throw new CayenneCryptoException("Error instantiating a cipher - no such padding: " + transformation, e); } } DefaultCipherFactory(@Inject(CryptoConstants.PROPERTIES_MAP) Map<String, String> properties); @Override Cipher cipher(); @Override int blockSize();  }