Ejemplo n.º 1
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.º 2
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.º 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;
  }