class HttpAuthUtil {

    static Cipher cipher(char[] masterPassword, byte[] salt, byte[] nonce, int cipherMode) throws HttpAuthException {
        try {
            SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
            KeySpec keySpec = new PBEKeySpec(masterPassword, salt, 10000, 256);
            SecretKeySpec spec = new SecretKeySpec(secretKeyFactory.generateSecret(keySpec).getEncoded(), "AES");
            Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
            cipher.init(cipherMode, spec, new GCMParameterSpec(128, nonce));

            return cipher;
        } catch (Exception e) {
            throw new HttpAuthException("Failed to prepare a cipher instance", e);
        }
    }

    private  HttpAuthUtil();

}