protected BlockCipher getCipher() { if (cipher == null) { cipher = new AES256(); cipher.initialize(BlockCipher.Direction.ENCRYPT, this); } return cipher; }
/** * Helps to create block cipher with a given class and key, by properly initializing it. * @param cipherClass cipher class to instantiate * @param key * @return properly initialized encpytor * @throws EncryptionError */ public static BlockCipher makeCipher(Class<? extends BlockCipher> cipherClass, byte[] key) throws EncryptionError { try { BlockCipher cipher = cipherClass.newInstance(); cipher.initialize(BlockCipher.Direction.DECRYPT, new SymmetricKey(key)); return cipher; } catch (InstantiationException | IllegalAccessException e) { throw new EncryptionError("failed to instantiate BlockCipher class " + cipherClass .getName(), e); } }