Example usage for org.apache.commons.codec.digest DigestUtils sha1Hex

List of usage examples for org.apache.commons.codec.digest DigestUtils sha1Hex

Introduction

In this page you can find the example usage for org.apache.commons.codec.digest DigestUtils sha1Hex.

Prototype

public static String sha1Hex(String data) 

Source Link

Usage

From source file:org.zaproxy.zap.extension.pscanrulesBeta.UsernameIdorScanner.java

@Override
public void scanHttpResponseReceive(HttpMessage msg, int id, Source source) {
    List<User> scanUsers = getUsers();
    if (scanUsers.isEmpty()) { // Should continue if not empty
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("There does not appear to be any contexts with configured users.");
        }/*from w  ww.j  av  a  2  s .c o  m*/
        return;
    }

    long start = System.currentTimeMillis();

    String response = msg.getResponseHeader().toString() + msg.getResponseBody().toString();
    String username;

    for (User user : scanUsers) {
        username = user.getName();
        Map<String, String> hashes = new HashMap<String, String>();
        hashes.put("MD2", DigestUtils.md2Hex(username));
        hashes.put("MD5", DigestUtils.md5Hex(username));
        hashes.put("SHA1", DigestUtils.sha1Hex(username));
        hashes.put("SHA256", DigestUtils.sha256Hex(username));
        hashes.put("SHA384", DigestUtils.sha384Hex(username));
        hashes.put("SHA512", DigestUtils.sha512Hex(username));
        for (Map.Entry<String, String> entry : hashes.entrySet()) {
            String hash = entry.getValue();
            String evidence = match(response, Pattern.compile(hash, Pattern.CASE_INSENSITIVE));
            if (evidence != null) {
                this.raiseAlert(username, evidence, entry.getKey(), id, msg);
            }
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("\tScan of record " + id + " took " + (System.currentTimeMillis() - start) + " ms");
    }
}

From source file:plum.encry.DefaultEncryption.java

/**
 * sha-1 encrption base64 chars.//w ww  . ja  v a 2s. c  om
 *
 * @param base64 base64 char
 * @return sha-1
 */
private static String sha_1(String base64) {
    return DigestUtils.sha1Hex(base64);
}

From source file:QueryStore.QueryStoreAPI.java

/**
 * Calculate the hash of a String/* ww  w .  j  a va  2s .  c  o  m*/
 *
 * @param input
 * @return
 */
private String calculateSHA1(String input) {
    if (input != null) {
        String hash = DigestUtils.sha1Hex(input);
        return hash;
    } else {
        return null;
    }
}

From source file:ren.hankai.cordwood.web.security.support.DefaultRequestInspector.java

@Override
public String signRequestParameters(Map<String, ?> parameters, String sk) {
    final String toBeSigned = buildSignText(parameters, sk);
    final String expSign = DigestUtils.sha1Hex(toBeSigned);
    return expSign;
}

From source file:ren.hankai.cordwood.web.security.support.DefaultRequestInspector.java

@Override
public String signRequestBody(String requestBody, String sk) {
    final String toBeSigned = requestBody + sk;
    final String expSign = DigestUtils.sha1Hex(toBeSigned);
    return expSign;
}

From source file:sd_mensajeria.GUI.Inicio_Sesion.java

private void btn_loginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_loginActionPerformed

    final Servicios s = new Servicios();
    final usuario UsuarioInfo = new usuario();
    if (txt_user.getText().equals("") || txt_password.getPassword() == null) {
        JOptionPane.showMessageDialog(null, "Debe llenar todos los campos", "No ha ingresado datos",
                JOptionPane.ERROR_MESSAGE);
    } else {//from   www  .  j a v  a  2 s  .c  o m
        if (txt_user.getText().matches("([a-z]|[A-Z]|[_]|[-])+") == false) {
            JOptionPane.showMessageDialog(null, "Ingrese simbolos validos", "Error en ingreso de datos",
                    JOptionPane.ERROR_MESSAGE);
        } else {
            String pass = txt_password.getText();
            String user = txt_user.getText();
            //buscar en los user el nombre del usuario                 
            String semilla = "2016";
            String encript = DigestUtils.sha1Hex(pass + semilla);

            try {
                if (s.validar_userName(user, encript, UsuarioInfo)) {
                    //if(s.validar_userName(user,pass, UsuarioInfo)){
                    this.setVisible(false);
                    try {
                        // TODO add your handling code here:
                        Receiver r = new Receiver(user, chatsActivos); // id+username del usuario que inicia sesin
                        ReceiverGrupo rg = new ReceiverGrupo(user, chatsActivos); // id+username del usuario que inicia sesin
                    } catch (Exception ex) {
                        Logger.getLogger(Inicio_Sesion.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    final String datos = UsuarioInfo.getNombre() + " " + UsuarioInfo.getApellido();
                    JOptionPane.showMessageDialog(null, "Bienvenid@!! " + datos, "Mensaje",
                            JOptionPane.INFORMATION_MESSAGE);
                    java.awt.EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            try {
                                new Principal(s, datos, UsuarioInfo, chatsActivos).setVisible(true);
                            } catch (IOException ex) {
                                Logger.getLogger(Inicio_Sesion.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    });
                } else {//user incorrecto
                    JOptionPane.showMessageDialog(null, "CREDENCIALES INCORRRECTAS", "Error en los datos",
                            JOptionPane.ERROR_MESSAGE);
                    txt_user.setText("");
                    txt_password.setText("");
                }
            } catch (IOException ex) {
                Logger.getLogger(Inicio_Sesion.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }
}

From source file:sd_mensajeria.GUI.Registro.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    final Servicios s = new Servicios();
    String nombre, apellido, ciudad, user, pass;
    String foto;//from w ww .  ja  v a2 s.  c  o  m

    nombre = txtNombre.getText();
    apellido = txtApellido.getText();
    user = txtUsuario.getText();
    pass = txtpass.getText();
    ciudad = (String) jComboBox1.getSelectedItem();
    foto = txtFoto.getText();

    if (nombre == null && apellido == null && ciudad == null && user == null && pass == null) {
        JOptionPane.showMessageDialog(null, "Debe llenar todos los campos", "No ha ingresado datos",
                JOptionPane.ERROR_MESSAGE);
    } else {
        String semilla = "2016";
        String encript = DigestUtils.sha1Hex(pass + semilla);

        if ("Ruta Foto".equals(foto)) {

            //System.out.println("Ninguna foto seleccionada..");
            try {
                s.registrar_usuario(nombre, apellido, ciudad, user, encript,
                        "C:\\Users\\Kattya Desiderio\\Documents\\GitHub\\SD_Mensajeria\\SD_Mensajeria\\src\\sd_conexion_bd\\avatar.jpg");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex);
            }

        } else {
            //System.out.println("Selecciono Foto...");
            try {
                s.registrar_usuario(nombre, apellido, ciudad, user, encript, foto);
            } catch (IOException ex) {
                Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        File file = null;
        if ("Ruta Foto".equals(foto)) {
            file = new File(
                    "C:\\Users\\Kattya Desiderio\\Documents\\GitHub\\SD_Mensajeria\\SD_Mensajeria\\src\\sd_conexion_bd\\avatar.jpg");
        } else {
            file = new File(foto);
        }
        Image im = null;

        try {
            im = javax.imageio.ImageIO.read(file);
        } catch (IOException ex) {
            Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex);
        }
        ImageIcon i = new ImageIcon(im.getScaledInstance(100, 120, 0));

        final usuario UsuarioInfo = new usuario();

        try {
            if (s.validar_userName(user, encript, UsuarioInfo)) {

                txtNombre.setText("");
                txtApellido.setText("");
                txtUsuario.setText("");
                txtpass.setText("");
                txtFoto.setText("");

                this.dispose();
                // this.setVisible(false);
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        try {

                            Principal p = new Principal(s, null, UsuarioInfo, chatsActivos);

                            p.setVisible(true);
                        } catch (IOException ex) {
                            Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                });
            }
        } catch (IOException ex) {
            Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}

From source file:servlet.login.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   w ww.  j a v  a  2s .  com*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, SQLException, ClassNotFoundException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */

        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title> Desarrollo</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("</body>");
        out.println("</html>");

        String U, P;

        U = request.getParameter("email");
        P = DigestUtils.sha1Hex(request.getParameter("pass"));

        DAO_usuario consultar = new DAO_usuario();
        Conexion con = new Conexion();
        if (!con.conectar()) {
            response.setContentType("text/html");

            out.println("<script type=\"text/javascript\">");
            out.println("alert('[ERROR] Al conectar');");

            out.println("</script>");

            out.println("<script type=\"text/javascript\">");
            out.println("window.location=\"iniciar_sesion.jsp\";");

            out.println("</script>");

        } else {

            if (!consultar.Usuario_Correcto(U, P)) {
                response.setContentType("text/html");
                out.println("<script type=\"text/javascript\">");
                out.println("alert('[ERROR] Al iniciar sesion.');");

                out.println("</script>");

                out.println("<script type=\"text/javascript\">");
                out.println("window.location=\"iniciar_sesion.jsp\";");

                out.println("</script>");

            } else {

                /*
                 ResultSet usuario;
                         
                 usuario =  consultar.Select_Usuario(U, P);
                         
                 String sexo,nickname;
                 sexo = usuario.getString("sexo");
                 nickname = usuario.getString("usuario");
                 int tipo_usuario = usuario.getInt("tipo_usuario");
                 */

                HttpSession mysesion = request.getSession();
                ServletContext ctx = getServletContext();

                mysesion.setAttribute("U", U);
                mysesion.setAttribute("P", P);
                /*
                mysesion.setAttribute("sexo",sexo);
                mysesion.setAttribute("tipo_usuario",tipo_usuario);
                mysesion.setAttribute("nickname",nickname);
                */
                RequestDispatcher dispatcher = ctx.getRequestDispatcher("/desarrollo.jsp");

                dispatcher.include(request, response);

            }
        }
    }
}

From source file:servlet.registrar.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w ww  . ja  va  2s.  c o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, SQLException, ClassNotFoundException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {

        out.println("<title>Conectando...</title>");
        Conexion con = new Conexion();
        if (!con.conectar()) {
            response.setContentType("text/html");
            out.println("<script type=\"text/javascript\">");
            out.println("alert('[ERROR] Al conectar');");

            out.println("</script>");

            out.println("<script type=\"text/javascript\">");
            out.println("window.location=\"index.jsp\";");

            out.println("</script>");

        } else {

            registro usuario = new registro();

            usuario.setEmail(request.getParameter("email"));
            usuario.setUsuario(request.getParameter("usuario"));
            usuario.setContrasena(DigestUtils.sha1Hex(request.getParameter("pass")));
            usuario.setSexo(request.getParameter("sexo"));
            usuario.setTipo_usuario(Integer.parseInt("0"));

            DAO_usuario Ingresar = new DAO_usuario();

            if (Ingresar.Usuario_valido(usuario)) {

                response.setContentType("text/html");
                out.println("<script type=\"text/javascript\">");
                out.println("alert('[ERROR] Email ya registrado.');");

                out.println("</script>");

                out.println("<script type=\"text/javascript\">");
                out.println("window.location=\"registrar.jsp\";");

                out.println("</script>");

            } else if (Ingresar.Insertar_usuario(usuario)) {

                response.setContentType("text/html");
                out.println("<script type=\"text/javascript\">");
                out.println("alert('[CORRECTO] Registrado Exitosamente.');");

                out.println("</script>");

                out.println("<script type=\"text/javascript\">");
                out.println("window.location=\"iniciar_sesion.jsp\";");

                out.println("</script>");
            } else {
                response.setContentType("text/html");
                out.println("<script type=\"text/javascript\">");
                out.println("alert('[ERROR] Al registrar su cuenta');");

                out.println("</script>");

                out.println("<script type=\"text/javascript\">");
                out.println("window.location=\"registrar.jsp\";");

                out.println("</script>");

            }
        }
    }
}

From source file:servlets.Login.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w ww  . jav  a  2 s . c o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession();
    if (AccessHelper.checkIfLoggedAsSomeone(session)) {
        response.sendRedirect("404");
    } else {
        boolean login_success = false;
        if ("POST".equals(request.getMethod())) {
            DbUser dbUser = new DbUser();

            HashMap fetchedUser = dbUser.accountAuthetication(request.getParameter("login"),
                    DigestUtils.sha1Hex(request.getParameter("password")));
            if (fetchedUser == null) {
                request.setAttribute("message", MessageHelper.generateDangerMessage(
                        "Wpisane dane s niepoprawne lub dane konto nie istnieje! <a href='register' class='alert-link'>Zaz konto na stronie rejestracji!</a>"));
            } else {
                SessionHelper.logInto(session, fetchedUser);
                login_success = true;
            }
        }

        if (login_success) {
            response.sendRedirect("main");
        } else {
            RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
            rd.forward(request, response);
        }
    }

}