Package org.rat.free.security.makifx.exception

Examples of org.rat.free.security.makifx.exception.BaseApplicationException


    }

    public <T> T loadJFXUI(@Nonnull final String resource) throws IOException, BaseApplicationException {
        URL url = instance.getClass().getResource(_BASE_ + resource);
        if (url == null) {
            throw new BaseApplicationException(
                    "URL not found, resource = " + _BASE_ + resource
                    + " please, don't use base resource path only like \'"
                    + "gui/foo.fxml\'")
                    .setErrorType(BaseApplicationException.ErrorType.ERROR);
        }
View Full Code Here


         * Cerca nel jar le classi che estendono AbstractPlugin e crea nuovi oggetti
         * iniettando istanze di manager (this) oppure del root_node, cioe' il nodo
         * radice salvato nella mappa cifrata.
         */
        if (manager == null) {
            throw new BaseApplicationException("Null manager interface.")
                    .setErrorType(BaseApplicationException.ErrorType.FATAL);
        }

        /**
         * Creo una lista di classi dei vari plugin.
         */
        List<AbstractPlugin> plugins = null;
        List<Class> list = null;
        try {
            list = listDataClasses(_PLUGIN_RESOURCE_PATH_);
            if (list == null || list.isEmpty()) {
                throw new BaseApplicationException("No plugin found.")
                        .setErrorType(BaseApplicationException.ErrorType.FATAL);
            }
        } catch (Exception exc) {
            throw new BaseApplicationException("Error during load plugin.")
                    .setErrorType(BaseApplicationException.ErrorType.FATAL);
        }

        /**
         * Istanzio i vari plugin, ed li inserisco in una lista che andro' ad
View Full Code Here

    @SuppressWarnings("UseSpecificCatch")
    public static void encryptFile(@Nonnull String pass, @Nonnull File file, @Nonnull String input) throws BaseApplicationException {

        if (pass == null) {
            throw new BaseApplicationException("Null Password invalid.")
                    .setErrorType(BaseApplicationException.ErrorType.FATAL);
        }
        if (pass.length() == 0) {
            throw new BaseApplicationException("Ivalid Password lenght.")
                    .setErrorType(BaseApplicationException.ErrorType.FATAL);
        }
        if (pass.length() > 16) {
            pass = pass.substring(0, 16);
        }

        try {
            pass = appendCPassData(pass);
        } catch (Exception exc) {
            throw new BaseApplicationException("Key Error!")
                    .setException(exc);
        }

        try {
            byte[] password = Utility.getUTF8Bytes(pass);
            ByteArrayInputStream secret
                    = new ByteArrayInputStream(Utility.getUTF8Bytes(input));

            OutputStream out = new FileOutputStream(file);
            byte[] buffer = new byte[1024];
            byte[] buff_of_iv_data = new byte[16];
            SecureRandom sc_r = new SecureRandom();
            sc_r.nextBytes(buff_of_iv_data);
            out.write(buff_of_iv_data);
            out.flush();

            SecretKeySpec sks = new SecretKeySpec(password, __KEY_SPEC);
            IvParameterSpec is = new IvParameterSpec(buff_of_iv_data);

            Cipher c = Cipher.getInstance(__CIP_MODE);
            c.init(Cipher.ENCRYPT_MODE, sks, is);

            out = new CipherOutputStream(out, c);

            @SuppressWarnings("UnusedAssignment")
            int n = 0;
            while ((n = secret.read(buffer)) >= 0) {
                out.write(buffer, 0, n);
            }
            out.flush();
            out.close();
        } catch (Exception exc) {
            Utility.log("Exception -encrypt- exc:" + exc);
            Utility.exc(exc);
            throw new BaseApplicationException("Encrypt Error!")
                    .setException(exc);
        }
    }
View Full Code Here

    public static String decryptFile(@Nonnull String pass, @Nonnull File file) throws BaseApplicationException {

        try {
            pass = appendCPassData(pass);
        } catch (Exception exc) {
            throw new BaseApplicationException("Key Error!")
                    .setException(exc);
        }

        try {

            StringBuilder o = new StringBuilder();

            try (InputStream in = new FileInputStream(file)) {
                byte[] password = Utility.getUTF8Bytes(pass);
                byte[] buffer = new byte[1024];
                byte[] buff_of_iv_data = new byte[16];
                in.read(buff_of_iv_data);

                SecretKeySpec sks = new SecretKeySpec(password, __KEY_SPEC);
                IvParameterSpec is = new IvParameterSpec(buff_of_iv_data);

                Cipher c = Cipher.getInstance(__CIP_MODE);
                c.init(Cipher.DECRYPT_MODE, sks, is);

                try (CipherInputStream ccin = new CipherInputStream(in, c)) {

                    @SuppressWarnings("UnusedAssignment")
                    int n = 0;

                    while ((n = ccin.read(buffer)) >= 0) {
                        o.append(new String(buffer, DEFAULT_CHARSET), 0, n);
                    }
                }
            }
            return o.toString();
        } catch (Exception exc) {
            Utility.log("Exception -decrypt- exc:" + exc);
            Utility.exc(exc);
            throw new BaseApplicationException("Decrypt Error!")
                    .setException(exc);
        }
    }
View Full Code Here

            m.setProperty(Marshaller.JAXB_ENCODING, DEFAULT_CHARSET);
            str_writer = new StringWriter();
            m.marshal(this, str_writer);
            return str_writer;
        } catch (Exception exc) {
            throw new BaseApplicationException(
                    "Marshal Error")
                    .setException(exc)
                    .setErrorType(BaseApplicationException.ErrorType.FATAL);
        } finally {
            if (str_writer != null) {
View Full Code Here

            return ksd;

        } catch (Exception exc) {
            Utility.log("Exception -decrypt- EXC: " + exc);
            Utility.exc(exc);
            throw new BaseApplicationException("Decrypt Error!").setException(exc);
        } finally {
            try {
                if (sr != null) {
                    sr.close();
                }
View Full Code Here

            String text_reloaded = AES.decryptFile(master_password, maki_file_map);
            EncryptedMap em = reloadEncryptedSavedData(text_reloaded);

            if (em == null) {
                log("SAVE - ecryptToFileFinally - ERROR EncryptedMap is NULL!");
                throw new BaseApplicationException(__ERROR_TEXT_UNMAR)
                        .setErrorType(BaseApplicationException.ErrorType.ERROR);
            }

            log("SAVE - ecryptToFileFinally DONE!");

        } catch (Exception exc) {
            Utility.warning("Error while saving user data. - ecryptToFileFinally - EXC: " + exc);
            Utility.exc(exc);
            exc.printStackTrace();
            throw new BaseApplicationException(__ERROR_TEXT_UNMAR)
                    .setErrorType(BaseApplicationException.ErrorType.ERROR);
        }
    }
View Full Code Here

        }

        log("FINE READ DATA SIZE:" + RIS.size());

        if (RIS.isEmpty()) {
            throw new BaseApplicationException("Can't login. Please check your username and password.")
                    .setErrorType(BaseApplicationException.ErrorType.WARNING);
        }
        return RIS.get(0);
    }
View Full Code Here

                }
            }
        } catch (Exception exc) {
            log("Exception -decodeEncFileMap- exc:" + exc);
            exc(exc);
            throw new BaseApplicationException("Can't login. Please check your username and password.")
                    .setErrorType(BaseApplicationException.ErrorType.ERROR);
        }

        if (!maki_file_map.exists()) {
            return firstEncyptedMap();
View Full Code Here

        /**
         * Se l'istanza del message digest, hash usato per mapping, e' nulla
         * allora si e' verificato un errore fatale.
         */
        if (message_digest == null) {
            throw new BaseApplicationException(
                    "Fatal Error, no such algorithm for message digest.")
                    .setErrorType(BaseApplicationException.ErrorType.FATAL);
        }

        try {

            // Per ovviare a differinti platform decodifico in UTF-8
            byte[] b_password = passwd;

            // Uso hash per tagliare i bytes AES (16 bytes)
            b_password = message_digest.digest(b_password);

            System.arraycopy(b_password, 0, b_password, 0, DEFAULT_AES_DIV_SIZE);
            SecretKeySpec sks = new SecretKeySpec(b_password, DEFAULT_ALGORITHM_CRY);

            return sks;

        } catch (Exception exc) {
            throw new BaseApplicationException(
                    "Fatal Error, impossible to generate key.\n"
                    + "Please check your Java installation.")
                    .setErrorType(BaseApplicationException.ErrorType.FATAL)
                    .setException(exc);
        }
View Full Code Here

TOP

Related Classes of org.rat.free.security.makifx.exception.BaseApplicationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.