Ejemplo n.º 1
0
  public static Respuesta codigoVerificacion(String codigo) {
    Respuesta retorno = new Respuesta();

    String md5Hash = "";
    try {
      MessageDigest md = MessageDigest.getInstance("MD5");
      md.update(codigo.getBytes());

      byte byteData[] = md.digest();

      // convert the byte to hex format method 1
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < byteData.length; i++) {
        sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
      }

      md5Hash = sb.toString();

      retorno.setOk(true);
      retorno.setDescripcion("Código verificación: " + md5Hash);
      retorno.setObjeto(md5Hash);
    } catch (Exception e) {
      retorno.setOk(false);
      retorno.setDescripcion("Error al generar el código de verificación\n" + e);
      retorno.setError(true);
    }
    return retorno;
  }
Ejemplo n.º 2
0
  public static Respuesta verificarMD5(String aVerificar, String originalMD5) throws Exception {
    Respuesta retorno = new Respuesta();
    Respuesta retornoHash = new Respuesta();
    String aVerificarMD5;

    try {
      retornoHash = hash(aVerificar);

      if (retornoHash.isOk()) {
        aVerificarMD5 = (String) retornoHash.getObjeto();

        if (aVerificarMD5.compareTo(originalMD5) == 0) {
          retorno.setOk(true);
          retorno.setDescripcion("Clave correcta");
          return retorno;
        } else {
          retorno.setOk(false);
          retorno.setDescripcion("Clave Incorrecta");
          return retorno;
        }
      } else {
        retorno.setOk(false);
        retorno.setDescripcion("Error al hashear la clave a verificar");
        retorno.setError(true);
        return retorno;
      }
    } catch (Exception e) {
      retorno.setOk(false);
      retorno.setDescripcion("Error al verificar la clave \n" + e);
      retorno.setError(true);
      return retorno;
    }
  }
Ejemplo n.º 3
0
  public static Respuesta hash(String password) throws Exception {
    Respuesta retorno = new Respuesta();

    String md5Hash = "";
    try {
      MessageDigest md = MessageDigest.getInstance("MD5");
      md.update(password.getBytes());

      byte byteData[] = md.digest();

      // convert the byte to hex format method 1
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < byteData.length; i++) {
        sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
      }

      md5Hash = sb.toString();

      retorno.setOk(true);
      retorno.setDescripcion("Clave hasheada: " + md5Hash);
      retorno.setObjeto(md5Hash);
    } catch (Exception e) {
      retorno.setOk(false);
      retorno.setDescripcion("Error al hashear la clave \n" + e);
      retorno.setError(true);
    }
    return retorno;
  }
Ejemplo n.º 4
0
 /**
  * Método estático que genera un código verificatorio nuevo
  *
  * <p>Registro de versiones:
  *
  * <ul>
  *   <li>1.0 18/03/2014 Francisco Hernandez (ATC Ltda): Versión inicial
  * </ul>
  *
  * @param rut int Rut de la persona
  * @param idFacebook String Identificador único de facebook
  * @return Objeto Respuesta con el string del cógido generado : ok=true si existoso, ok=false en
  *     caso contrario, y descripcion, error=true si hay error.
  * @since 1.0
  */
 public static Respuesta generaCodigoVerificacion(int rut, String idFacebook) {
   Respuesta retorno = new Respuesta();
   Log logger = new Log("MD5Hashing", "generaCodigoVerificacion()");
   Date fecha = new Date();
   String codigoPrevio = rut + "-" + fecha.toString() + "-" + idFacebook;
   Respuesta respCodigo = codigoVerificacion(codigoPrevio);
   if (respCodigo.isOk()) {
     String codigoListo = (String) respCodigo.getObjeto();
     retorno.setOk(true);
     retorno.setDescripcion(respCodigo.getDescripcion());
     retorno.setObjeto(codigoListo);
     logger.debug(respCodigo.getDescripcion());
   } else {
     retorno.setOk(false);
     retorno.setDescripcion(respCodigo.getDescripcion());
     logger.debug(respCodigo.getDescripcion());
   }
   return retorno;
 }