Example usage for java.security NoSuchAlgorithmException getLocalizedMessage

List of usage examples for java.security NoSuchAlgorithmException getLocalizedMessage

Introduction

In this page you can find the example usage for java.security NoSuchAlgorithmException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.openintents.safe.CryptoHelper.java

/**
 * @return/*  w  w  w  . j ava2 s . c o m*/
 */
private String getTemporaryFileName() throws CryptoHelperException {
    String randomPart;
    try {
        // create a random session name
        randomPart = generateSalt();
    } catch (NoSuchAlgorithmException e1) {
        e1.printStackTrace();
        String msg = "Decrypt error: " + e1.getLocalizedMessage();
        throw new CryptoHelperException(msg);
    }

    return Environment.getExternalStorageDirectory().toString() + "/tmp-" + randomPart;
}

From source file:org.openintents.safe.CryptoHelper.java

/**
 * Dencrypt a file previously encrypted with
 * encryptFileWithSessionKey()./* w  w w . ja  va2 s.c  om*/
 * <p/>
 * The original file is not modified
 *
 * @param ctx     Context of activity in order to store temp file
 * @param fileUri Uri to either a stream or a file to read from
 * @return If decryption is successful, returns Uri of a content
 * provider to read the plaintext file.  Upon failure,
 * return null.
 * @throws Exception
 * @author Peli
 */
public Uri decryptFileWithSessionKeyThroughContentProvider(Context ctx, Uri fileUri)
        throws CryptoHelperException {
    if (debug) {
        Log.d(TAG, "fileUri=" + fileUri.toString());
    }
    ContentResolver contentResolver = ctx.getContentResolver();

    String sessionFile = "";
    Uri resultUri = null;
    boolean result = false;

    try {
        InputStream is;
        if (fileUri.getScheme().equals("file")) {
            is = new java.io.FileInputStream(fileUri.getPath());
            if (debug) {
                Log.d(TAG, "Decrypt: Input from " + fileUri.getPath());
            }
        } else {
            is = contentResolver.openInputStream(fileUri);
            if (debug) {
                Log.d(TAG, "Decrypt: Input from " + fileUri.toString());
            }
        }
        FileOutputStream os = null;

        String decryptSession;
        try {
            // create a random session name
            decryptSession = generateSalt();
        } catch (NoSuchAlgorithmException e1) {
            e1.printStackTrace();
            String msg = "Decrypt error: " + e1.getLocalizedMessage();
            throw new CryptoHelperException(msg);
        }
        sessionFile = CryptoContentProvider.SESSION_FILE + "." + decryptSession;
        if (debug) {
            Log.d(TAG, "Decrypt: Output to " + sessionFile);
        }

        // openFileOutput creates a file in /data/data/{packagename}/files/
        // In our case, /data/data/org.openintents.safe/files/
        // This file is owned and only readable by our application
        os = ctx.openFileOutput(sessionFile, Context.MODE_PRIVATE);

        // after writing the decrypted content to a temporary file,
        // pass back a Uri that can be used to read back the contents
        resultUri = Uri.withAppendedPath(CryptoContentProvider.CONTENT_URI, "decrypt/" + decryptSession);

        result = decryptStreamWithSessionKey(is, os);

        // Close the input stream
        is.close();
        os.close();

    } catch (FileNotFoundException e) {
        Log.e(TAG, "File not found", e);
    } catch (IOException e) {
        Log.e(TAG, "IOException", e);
    }

    if (result == false) {
        resultUri = null;

        // Unsuccessful. Clean up
        ctx.deleteFile(sessionFile);
    }

    return resultUri;
}

From source file:com.microsoft.rightsmanagement.sampleapp.MsipcTaskFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mApplicationContext = getActivity().getApplicationContext();
    // Retain this fragment across configuration changes.
    setRetainInstance(true);// w  ww . j a  v  a  2  s .  c  o  m
    updateTaskStatus(new TaskStatus(TaskState.NotStarted, null, false));
    mConsentCallback = getConsentCallback();
    try {
        mRmsAuthCallback = App.getInstance().getRmsAuthenticationCallback(getActivity());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        Logger.ie(TAG, e.getMessage());
        updateTaskStatus(new TaskStatus(TaskState.Faulted, e.getLocalizedMessage(), true));
    } catch (InvalidKeySpecException e) {
        e.printStackTrace();
        Logger.ie(TAG, e.getMessage());
        updateTaskStatus(new TaskStatus(TaskState.Faulted, e.getLocalizedMessage(), true));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        Logger.ie(TAG, e.getMessage());
        updateTaskStatus(new TaskStatus(TaskState.Faulted, e.getLocalizedMessage(), true));
    }
}

From source file:staging.plugin.StagingUtils.java

public static final String copyWithMD5Digest(IFileStore source, IFileStore destination, IFileInfo sourceInfo,
        IProgressMonitor monitor) throws CoreException {
    // TODO honor cancellation requests during copy
    // TODO report progress
    log.debug("source: {}", source);
    log.debug("destination: {}", destination);
    // monitor.subTask("Copying file " + source.getName() + "...");
    String result = null;/*from w ww.j  a v a  2  s  . c  o  m*/
    byte[] buffer = new byte[chunkSize];
    int length = (int) sourceInfo.getLength();
    int progressTickBytes = length / 100;
    int bytesRead = 0;
    int totalBytesCopied = 0;
    InputStream in = null;
    OutputStream out = null;
    try {
        MessageDigest messageDigest;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new CoreException(new Status(Status.ERROR, StagingPlugin.PLUGIN_ID,
                    "Cannot compare checksums without MD5 algorithm.", e));
        }
        messageDigest.reset();
        in = new BufferedInputStream(source.openInputStream(EFS.NONE, null), 1024 * 64);
        destination.getParent().mkdir(EFS.NONE, null);
        out = new BufferedOutputStream(destination.openOutputStream(EFS.NONE, null), 1024 * 64);
        while ((bytesRead = in.read(buffer, 0, chunkSize)) != -1) {
            if (monitor.isCanceled()) {
                throw new CoreException(
                        new Status(IStatus.CANCEL, StagingPlugin.PLUGIN_ID, "Staging cancelled"));
            }
            out.write(buffer, 0, bytesRead);
            messageDigest.update(buffer, 0, bytesRead);
            totalBytesCopied = totalBytesCopied + bytesRead;
            if (totalBytesCopied > 0 && progressTickBytes > 0) {
                if ((totalBytesCopied % progressTickBytes) < bytesRead) {
                    monitor.worked(1);
                    // if (length > 0) {
                    // int percent = (int) (100.0 * ((float)
                    // totalBytesCopied / length));
                    // monitor.subTask(percent + "% (" + totalBytesCopied /
                    // 1024 + "/" + length / 1024 + "K)");
                    // }
                }
            }
        }
        Hex hex = new Hex();
        result = new String(hex.encode(messageDigest.digest()));
    } catch (IOException e) {
        throw new CoreException(new Status(Status.ERROR, StagingPlugin.PLUGIN_ID, e.getLocalizedMessage(), e));
    } finally {
        try {
            if (out != null) {
                out.flush();
                out.close();
            }
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
            log.error("Trouble closing i/o resources", e);
        }
    }
    return result;
}

From source file:com.smartmarmot.dbforbix.config.Config.java

/**
 * calculates hash for config file//w  w w. j  av  a2  s  .  c o  m
 * @throws NullPointerException - if hash is null
 */
private void calculateFileConfigHash() throws NullPointerException {
    MessageDigest md = null;
    byte[] b = new byte[2048];
    try {
        md = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        LOG.error("Wrong algorithm provided while getting instance of MessageDigest: " + e.getMessage());
    }
    /**
     * try with resources. Autoclosing after exitting try block
     */
    try (InputStream is = Files.newInputStream(Paths.get(getConfigFile()));
            DigestInputStream dis = new DigestInputStream(is, md)) {
        while (dis.read(b) >= 0)
            ;
    } catch (IOException e) {
        LOG.error("Something has happenned reading file: " + e.getLocalizedMessage());
    }
    try {
        setFileConfigHash((new HexBinaryAdapter()).marshal(md.digest()));
    } catch (Exception e) {
        LOG.error("Something has happenned converting md5 sum to string: " + e.getLocalizedMessage());
    }
    if (null == getFileConfigHash())
        throw new NullPointerException("Hash for config file is null!");
}

From source file:org.talend.repository.RepositoryService.java

private boolean isloginDialogDisabled() {
    boolean reload = Boolean.parseBoolean(System.getProperty("talend.project.reload")); //$NON-NLS-1$
    PreferenceManipulator preferenceManipulator = new PreferenceManipulator();
    ConnectionBean lastBean = null;/*from   w w  w.  j a va2  s  .  c o  m*/
    if (reload) {
        final ConnectionUserPerReader instance = ConnectionUserPerReader.getInstance();
        instance.forceReadConnections();
        final String lastConncetion = ConnectionUserPerReader.getInstance().readLastConncetion();
        for (ConnectionBean bean : instance.readConnections()) {
            if (bean.getName().equals(lastConncetion)) {
                lastBean = bean;
                break;
            }
        }
    }

    if (ArrayUtils.contains(Platform.getApplicationArgs(),
            EclipseCommandLine.TALEND_DISABLE_LOGINDIALOG_COMMAND)) {
        boolean deleteProjectIfExist = ArrayUtils.contains(Platform.getApplicationArgs(),
                "--deleteProjectIfExist"); //$NON-NLS-1$
        IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault()
                .getService(IBrandingService.class);
        brandingService.getBrandingConfiguration().setUseProductRegistration(false);
        ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();

        String projectName = getAppArgValue("-project", "AUTO_LOGIN_PROJECT"); //$NON-NLS-1$ //$NON-NLS-2$
        String language = getAppArgValue("-language", ECodeLanguage.JAVA.getName()); //$NON-NLS-1$
        String login = getAppArgValue("-login", "auto@login.com"); //$NON-NLS-1$ //$NON-NLS-2$
        String password = getAppArgValue("-loginPass", ""); //$NON-NLS-1$ //$NON-NLS-2$
        String tacURL = getAppArgValue("-tacURL", null); //$NON-NLS-1$
        // if tacURL is null, the branch will be no useful.
        String branch = getAppArgValue("-branch", null); //$NON-NLS-1$
        // if tacURL is not null, will be remote
        final boolean isRemote = tacURL != null;

        if (reload && lastBean != null) {
            final String lastProject = preferenceManipulator.getLastProject();
            if (lastProject != null) {
                projectName = lastProject;
            }
            final String lastSVNBranch = preferenceManipulator.getLastSVNBranch();
            if (lastSVNBranch != null) {
                branch = lastSVNBranch;
            }
            final String lastUser = lastBean.getUser();
            if (lastUser != null) {
                login = lastUser;
            }
            final String lastPass = lastBean.getPassword();
            if (lastPass != null) {
                password = lastPass;
            }

        }

        User userInfo = PropertiesFactoryImpl.eINSTANCE.createUser();
        userInfo.setLogin(login);
        try {
            userInfo.setPassword(PasswordHelper.encryptPasswd(password));
        } catch (NoSuchAlgorithmException e) {
            ExceptionHandler.process(e);
        }

        try {
            ConnectionBean bean = null;

            if (reload && lastBean != null) {// reload
                bean = lastBean;
            } else {
                if (tacURL != null && isRemote) { // remote
                    bean = ConnectionBean.getDefaultRemoteConnectionBean();
                    bean.setUser(login);
                    bean.setPassword(password);
                    bean.getDynamicFields().put(RepositoryConstants.REPOSITORY_URL, tacURL);
                } else {
                    bean = ConnectionBean.getDefaultConnectionBean();
                }
            }

            Context ctx = CorePlugin.getContext();
            RepositoryContext repositoryContext = new RepositoryContext();
            ctx.putProperty(Context.REPOSITORY_CONTEXT_KEY, repositoryContext);

            repositoryContext.setUser(userInfo);
            repositoryContext.setClearPassword(password);
            repositoryContext.setFields(bean.getDynamicFields());

            repositoryFactory.setRepositoryFactoryFromProvider(
                    RepositoryFactoryProvider.getRepositoriyById(bean.getRepositoryId()));
            Project project = null;
            for (Project p : repositoryFactory.readProject()) {
                if (p.getLabel().equals(projectName) || p.getTechnicalLabel().equals(projectName)) {
                    project = p;
                    break;
                }
            }
            if (project != null && branch != null) {
                ProjectManager.getInstance().setMainProjectBranch(project, branch);

            }
            if (!reload) {
                if (deleteProjectIfExist && project != null) {
                    IWorkspace workspace = ResourcesPlugin.getWorkspace();
                    IProject eclipseProject = workspace.getRoot().getProject(project.getTechnicalLabel());
                    if (eclipseProject.exists()) {
                        eclipseProject.delete(true, new NullProgressMonitor());
                    }
                }
                if (!isRemote && (project == null || deleteProjectIfExist)) {
                    Project projectInfor = ProjectHelper.createProject(projectName, "", //$NON-NLS-1$
                            language, userInfo);
                    project = repositoryFactory.createProject(projectInfor);
                }
            } else {
                if (project != null && !project.getEmfProject().isLocal()
                        && repositoryFactory.isLocalConnectionProvider()) {
                    List<IRepositoryFactory> rfList = RepositoryFactoryProvider.getAvailableRepositories();
                    IRepositoryFactory remoteFactory = null;
                    for (IRepositoryFactory rf : rfList) {
                        if (!rf.isLocalConnectionProvider()) {
                            remoteFactory = rf;
                            break;
                        }
                    }
                    if (remoteFactory != null) {
                        repositoryFactory.setRepositoryFactoryFromProvider(remoteFactory);
                        repositoryFactory.getRepositoryContext().setOffline(true);
                    }
                }

            }
            if (project == null) {
                throw new LoginException(Messages.getString("RepositoryService.projectNotFound", projectName)); //$NON-NLS-1$
            }
            repositoryContext.setProject(project);

            repositoryFactory.logOnProject(project, new NullProgressMonitor());
        } catch (final PersistenceException e) {
            if (e instanceof OperationCancelException) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(),
                                Messages.getString("LoginDialog.logonCanceled"), e.getLocalizedMessage());
                    }

                });
            } else {
                MessageBoxExceptionHandler.process(e, new Shell());
            }
            repositoryFactory.logOffProject();
            return false;
        } catch (LoginException e) {
            MessageBoxExceptionHandler.process(e, new Shell());
            repositoryFactory.logOffProject();
            return false;
        } catch (BusinessException e) {
            MessageBoxExceptionHandler.process(e, new Shell());
            repositoryFactory.logOffProject();
            return false;
        } catch (CoreException e) {
            MessageBoxExceptionHandler.process(e, new Shell());
            repositoryFactory.logOffProject();
            return false;
        }

        return true;
    }
    return false;
}

From source file:de.rrze.idmone.utils.jpwgen.PwGenerator.java

/**
 * This method parses the command line options, initializes the needed
 * objects and generates the required number of passwords by calling
 * <em>generatePassword()</em>. When not used as a stand-alone program this
 * method is to be preferred instead of the main(String[]).
 * //from  w w w  . java  2s.c o m
 * @param args
 *            the arguments used to initialize the generation process
 * @return a list of passwords or <em>null</em> if no suitable passwords
 *         could be generated.
 */

public static synchronized List<String> process(String[] args) {
    int passwordFlags = initDefaultFlags();

    // The length of the password to be generated
    int passwordLength = DEFAULT_PASSWORD_LENGTH;

    int numberOfPasswords = DEFAULT_NUMBER_OF_PASSWORDS;

    int maxAttempts = DEFAULT_MAX_ATTEMPTS;

    log(Messages.getString("PwGenerator.PASSWORD_GENERATOR"), //$NON-NLS-1$
            false);

    ArrayList<String> passwords = new ArrayList<String>();
    BasicParser parser = new BasicParser();
    try {
        CommandLine commandLine = parser.parse(options, args);

        parser.parse(options, args);
        if (commandLine.hasOption(CL_HELP)) {
            printUsage();
            log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$
                    false);
            return passwords;
        }

        parser.parse(options, args);
        if (commandLine.hasOption(CL_SR_PROVIDERS)) {
            Set<String> serviceProviders = RandomFactory.getInstance()
                    .getServiceProviderFor(IRandomFactory.TYPE_SECURE_RANDOM);
            log(Messages.getString("PwGenerator.SERVICES_PROVIDERS_FOR") //$NON-NLS-1$
                    + IRandomFactory.TYPE_SECURE_RANDOM + Messages.getString("PwGenerator.NEW_LINE"), false); //$NON-NLS-1$
            for (Iterator<String> iter = serviceProviders.iterator(); iter.hasNext();) {
                String element = (String) iter.next();
                log(Messages.getString("PwGenerator.SERVICE_PROVIDERS") + element //$NON-NLS-1$
                        + Messages.getString("PwGenerator.NEW_LINE"), false); //$NON-NLS-1$
                log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$
                        false);
                return passwords;
            }
        }

        parser.parse(options, args);
        if (commandLine.hasOption(CL_PROVIDERS)) {
            log(Messages.getString("PwGenerator.ALL_SEC_PROVIDERS") //$NON-NLS-1$
                    + IRandomFactory.TYPE_SECURE_RANDOM + Messages.getString("PwGenerator.NEW_LINE"), false); //$NON-NLS-1$
            Provider[] serviceProviders = RandomFactory.getInstance().getProviders();
            for (int i = 0; i < serviceProviders.length; i++) {
                log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$
                        false);
                log(Messages.getString("PwGenerator.PROVIDER") + serviceProviders[i].getName() //$NON-NLS-1$
                        + Messages.getString("PwGenerator.NEW_LINE"), //$NON-NLS-1$
                        false);
                Set<Provider.Service> services = serviceProviders[i].getServices();
                log(Messages.getString("PwGenerator.SERVICES") + Messages.getString("PwGenerator.NEW_LINE"), //$NON-NLS-1$//$NON-NLS-2$
                        false);
                log(services.toString(), false);
                log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$
                        false);
            }
            log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$
                    false);
            return passwords;
        }

        if (commandLine.hasOption(CL_NUMBER_PASSWORD)) {
            String sNumberOfPasswords = commandLine.getOptionValue(CL_NUMBER_PASSWORD);
            if (sNumberOfPasswords != null)
                numberOfPasswords = Integer.parseInt(sNumberOfPasswords);
            log(Messages.getString("PwGenerator.NUM_PASSWORDS") + numberOfPasswords, false); //$NON-NLS-1$
        }

        commandLine = parser.parse(options, args);
        if (commandLine.hasOption(CL_PASSWORD_LENGTH)) {
            String sPasswordLength = commandLine.getOptionValue(CL_PASSWORD_LENGTH);
            if (sPasswordLength != null)
                passwordLength = Integer.parseInt(sPasswordLength);
            log(Messages.getString("PwGenerator.PASSWORD_LENGTH") + passwordLength, false); //$NON-NLS-1$
        }

        parser.parse(options, args);
        if (commandLine.hasOption(CL_COLUMN)) {
            doColumns = true;
            log(Messages.getString("PwGenerator.COLUMNS_ENABLED"), false); //$NON-NLS-1$
        }

        parser.parse(options, args);
        if (commandLine.hasOption(CL_TERM_WIDTH)) {
            String sTermWidth = commandLine.getOptionValue(CL_TERM_WIDTH);
            if (sTermWidth != null)
                termWidth = Integer.parseInt(sTermWidth);
            log(Messages.getString("PwGenerator.TERMINAL_LENGTH") + termWidth, false); //$NON-NLS-1$
        }

        Random random = null;
        parser.parse(options, args);
        if (commandLine.hasOption(CL_RANDOM)) {
            random = RandomFactory.getInstance().getRandom();
            log(Messages.getString("PwGenerator.NORMAL_RANDOM"), false); //$NON-NLS-1$
        } else {
            try {
                random = RandomFactory.getInstance().getSecureRandom();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
                random = RandomFactory.getInstance().getRandom();
            } catch (NoSuchProviderException e) {
                e.printStackTrace();
                random = RandomFactory.getInstance().getRandom();
            }
        }

        parser.parse(options, args);
        if (commandLine.hasOption(CL_SR_ALGORITHM)) {
            String[] data = commandLine.getOptionValues(CL_SR_ALGORITHM);
            if (data.length == 2) {
                try {
                    random = RandomFactory.getInstance().getSecureRandom(data[0], data[1]);

                    log(Messages.getString("PwGenerator.SEC_ALG") + data[0] //$NON-NLS-1$
                            + Messages.getString("PwGenerator.PROV") + data[1] //$NON-NLS-1$
                            + Messages.getString("PwGenerator.DOR"), false); //$NON-NLS-1$
                } catch (NoSuchAlgorithmException e) {
                    log(Messages.getString("PwGenerator.ERROR") + e.getMessage() //$NON-NLS-1$
                            + Messages.getString("PwGenerator.NEW_LINE"), true); //$NON-NLS-1$
                    log(Messages.getString("PwGenerator.DEFAUL_RANDOM"), true); //$NON-NLS-1$
                } catch (NoSuchProviderException e) {
                    log(Messages.getString("PwGenerator.ERROR") + e.getMessage() //$NON-NLS-1$
                            + Messages.getString("PwGenerator.NEW_LINE"), true); //$NON-NLS-1$
                    log(Messages.getString("PwGenerator.DEFAUL_RANDOM"), true); //$NON-NLS-1$
                }
            }
        }

        if (commandLine.hasOption(CL_NUMERALS)) {
            passwordFlags |= PW_DIGITS;
            log(Messages.getString("PwGenerator.DIGITS_ON"), false); //$NON-NLS-1$
        }

        if (commandLine.hasOption(CL_NO_NUMERALS)) {
            passwordFlags &= ~PW_DIGITS;
            log(Messages.getString("PwGenerator.DIGITS_OFF"), false); //$NON-NLS-1$
        }

        if (commandLine.hasOption(CL_CAPITALIZE)) {
            passwordFlags |= PW_UPPERS;
            log(Messages.getString("PwGenerator.UPPERCASE_ON"), false); //$NON-NLS-1$
        }

        if (commandLine.hasOption(CL_NO_CAPITALIZE)) {
            passwordFlags &= ~PW_UPPERS;
            log(Messages.getString("PwGenerator.UPPERCASE_OFF"), false); //$NON-NLS-1$
        }

        if (commandLine.hasOption(CL_AMBIGOUS)) {
            passwordFlags |= PW_AMBIGUOUS;
            log(Messages.getString("PwGenerator.AMBIGOUS_ON"), false); //$NON-NLS-1$
        }

        if (commandLine.hasOption(CL_NO_AMBIGOUS)) {
            passwordFlags &= ~PW_AMBIGUOUS;
            log(Messages.getString("PwGenerator.AMBIGOUS_OFF"), false); //$NON-NLS-1$
        }

        if (commandLine.hasOption(CL_SYMBOLS)) {
            passwordFlags |= PW_SYMBOLS;
            log(Messages.getString("PwGenerator.SYMBOLS_ON"), false); //$NON-NLS-1$
        }

        if (commandLine.hasOption(CL_SYMBOLS_REDUCED)) {
            passwordFlags |= PW_SYMBOLS_REDUCED;
            log(Messages.getString("PwGenerator.SYMBOLS_REDUCED_ON"), false); //$NON-NLS-1$
        }

        if (commandLine.hasOption(CL_NO_SYMBOLS)) {
            passwordFlags &= ~PW_SYMBOLS;
            passwordFlags &= ~PW_SYMBOLS_REDUCED;
            log(Messages.getString("PwGenerator.SYMBOLS_OFF"), false); //$NON-NLS-1$
        }

        if (commandLine.hasOption(CL_MAX_ATTEMPTS)) {
            String sMaxAttempts = commandLine.getOptionValue(CL_MAX_ATTEMPTS);
            if (sMaxAttempts != null)
                maxAttempts = Integer.parseInt(sMaxAttempts);
            log(Messages.getString("PwGenerator.MAX_ATTEMPTS") + maxAttempts, false); //$NON-NLS-1$
        }

        if (commandLine.hasOption(CL_REGEX_STARTS_NO_SMALL_LETTER))
            passwordFlags |= REGEX_STARTS_NO_SMALL_LETTER_FLAG;

        if (commandLine.hasOption(CL_REGEX_ENDS_NO_SMALL_LETTER))
            passwordFlags |= REGEX_STARTS_NO_SMALL_LETTER_FLAG;

        if (commandLine.hasOption(CL_REGEX_STARTS_NO_UPPER_LETTER))
            passwordFlags |= REGEX_STARTS_NO_UPPER_LETTER_FLAG;

        if (commandLine.hasOption(CL_REGEX_ENDS_NO_UPPER_LETTER))
            passwordFlags |= REGEX_ENDS_NO_UPPER_LETTER_FLAG;

        if (commandLine.hasOption(CL_REGEX_ENDS_NO_DIGIT))
            passwordFlags |= REGEX_ENDS_NO_DIGIT_FLAG;

        if (commandLine.hasOption(CL_REGEX_STARTS_NO_DIGIT))
            passwordFlags |= REGEX_STARTS_NO_DIGIT_FLAG;

        if (commandLine.hasOption(CL_REGEX_STARTS_NO_SYMBOL))
            passwordFlags |= REGEX_STARTS_NO_SYMBOL_FLAG;

        if (commandLine.hasOption(CL_REGEX_ENDS_NO_SYMBOL))
            passwordFlags |= REGEX_ENDS_NO_SYMBOL_FLAG;

        if (commandLine.hasOption(CL_REGEX_ONLY_1_CAPITAL))
            passwordFlags |= REGEX_ONLY_1_CAPITAL_FLAG;

        if (commandLine.hasOption(CL_REGEX_ONLY_1_SYMBOL))
            passwordFlags |= REGEX_ONLY_1_SYMBOL_FLAG;

        if (commandLine.hasOption(CL_REGEX_AT_LEAST_2_SYMBOLS))
            passwordFlags |= REGEX_AT_LEAST_2_SYMBOLS_FLAG;

        if (commandLine.hasOption(CL_REGEX_ONLY_1_DIGIT))
            passwordFlags |= REGEX_ONLY_1_DIGIT_FLAG;

        if (commandLine.hasOption(CL_REGEX_AT_LEAST_2_DIGITS))
            passwordFlags |= REGEX_AT_LEAST_2_DIGITS_FLAG;
        // -------------------------------------------------------------------

        log(Messages.getString("PwGenerator.GENRIC_FLAGS"), //$NON-NLS-1$
                false);

        int res = passwordFlags & PW_DIGITS;
        log(Messages.getString("PwGenerator.DIGITS") + (res != 0), false); //$NON-NLS-1$
        res = passwordFlags & PW_AMBIGUOUS;
        log(Messages.getString("PwGenerator.AMBIGOUS") + (res != 0), false); //$NON-NLS-1$
        res = passwordFlags & PW_SYMBOLS;
        log(Messages.getString("PwGenerator.SYMBOLS") + (res != 0), false); //$NON-NLS-1$
        res = passwordFlags & PW_SYMBOLS_REDUCED;
        log(Messages.getString("PwGenerator.SYMBOLS_REDUCED") + (res != 0), false); //$NON-NLS-1$
        res = passwordFlags & PW_UPPERS;
        log(Messages.getString("PwGenerator.UPPERS") + (res != 0), false); //$NON-NLS-1$
        log(Messages.getString("PwGenerator.SEPARATOR"), //$NON-NLS-1$
                false);

        log(Messages.getString("PwGenerator.GENERATING") + numberOfPasswords //$NON-NLS-1$
                + Messages.getString("PwGenerator.PW_LENGTH") //$NON-NLS-1$
                + passwordLength, false);
        log(Messages.getString("PwGenerator.PW"), //$NON-NLS-1$
                false);

        int i;
        for (i = 0; i < numberOfPasswords; i++) {
            String password = generatePassword(passwordLength, passwordFlags, maxAttempts, random);
            if (password != null)
                passwords.add(password);
        }
    } catch (ParseException e) {
        log(Messages.getString("PwGenerator.PARAM_ERROR") + e.getLocalizedMessage(), true); //$NON-NLS-1$
        printUsage();
    } catch (NumberFormatException e) {
        log(Messages.getString("PwGenerator.NUM_FORM_ERROR") + e.getLocalizedMessage(), true); //$NON-NLS-1$
        printUsage();
    }

    return passwords;
}