code: private static Cipher createCipher(final String algorithm, final int mode, final char[] password, final byte[] salt, final int count)
              throws GeneralSecurityException {
  
          final SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
          final PBEKeySpec keySpec = new PBEKeySpec(password);
          final SecretKey key = keyFactory.generateSecret(keySpec);
          final Cipher cipher = Cipher.getInstance(algorithm);
          final PBEParameterSpec params = new PBEParameterSpec(salt, count);
          cipher.init(mode, key, params);
          return cipher;
  
      }
docs: Creates a cipher for encryption or decryption.
  
  @param algorithm
  PBE algorithm like "PBEWithMD5AndDES" or "PBEWithMD5AndTripleDES".
  @param mode
  Encyrption or decyrption.
  @param password
  Password.
  @param salt
  Salt usable with algorithm.
  @param count
  Iterations.
  
  @return Ready initialized cipher.
  
  @throws GeneralSecurityException
  Error creating the cipher.