Fórum Criptografia Java #573438

03/01/2017

0

Fala galera!

Alguém ai perito em autenticação e criptografia java?
Tenho esse código aqui e queria remover a autenticação e tirar a criptografia md5, SHA1 e deixar somente o codigo aberto.
Só para terem uma ideia esse codigo faz leitura do serial HD, CPU e DATA e gera uma inf

package godauthentication;

import java.io.PrintStream;

public class Main
{
  public static void main(String[] args)
  {
    try
    {
      verify n = new verify();
      int cont = n.controladora();
      if (cont == 1)
      {
        System.out.println("valido");
      }
      else if (cont == 3)
      {
        System.out.println("valido com failover");
      }
      else
      {
        n.geraInfo();
        System.out.println("invalido");
      }
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }
}


package godauthentication;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.net.SocketException;
import java.util.Date;

public class verify
{
  public String leRegistro()
    throws Exception
  {
    FileReader fr = new FileReader("mail.lic");
    BufferedReader br = new BufferedReader(fr);
    String linha = null;
    linha = br.readLine();
    return linha;
  }
  
  final DesHelper seg = new DesHelper("Godoyers");
  
  public void geraInfo()
    throws IOException
  {
    byte[] b = null;
    String g = "";
    String h = "";
    try
    {
      b = registra.getComputerIdentifier();
      g = registra.getCPUSerial().replaceAll("-", "&");
      h = registra.getHDSerial("c").replaceAll("-", "b");
    }
    catch (SocketException ex)
    {
      System.out.println("erro ao ler registro!");
    }
    String a = g + "-" + h;
    String c = this.seg.encrypt(a);
    
    FileWriter fw = new FileWriter("info.txt");
    
    fw.write(c);
    fw.close();
  }
  
  public void renameFile(String fileIn, String fileOut)
  {
    File arquivo = new File(System.getProperty("user.dir") + "\\\\" + fileIn);
    File dir = new File(System.getProperty("user.dir"));
    arquivo.renameTo(new File(dir, fileOut));
  }
  
  public String getlicenca()
  {
    try
    {
      FileReader fr = new FileReader("decio.lic");
      BufferedReader br = new BufferedReader(fr);
      String linha = "";
      linha = br.readLine();
      return this.seg.decrypt(linha);
    }
    catch (Exception ex) {}
    return "";
  }
  
  public boolean checkHardware()
  {
    try
    {
      tijolo t = new tijolo();
      byte[] b = null;
      String g = "";
      String h = "";
      try
      {
        b = registra.getComputerIdentifier();
        g = registra.getCPUSerial().replaceAll("-", "&");
        h = registra.getHDSerial("c").replaceAll("-", "b");
      }
      catch (Exception ex)
      {
        System.out.println("erro ao ler registro!");
        return false;
      }
      String a = g + "-" + h;
      String c = this.seg.encrypt(a);
      
      String l = "";
      try
      {
        if (!getlicenca().equalsIgnoreCase(""))
        {
          l = getlicenca();
          String[] coluna = l.split("-");
          t.setCpu(coluna[0]);
          t.setHd(coluna[1]);
          t.setData(coluna[2]);
          t.setObj1(coluna[3]);
          t.setObj2(coluna[4]);
          t.setObj3(coluna[5]);
          t.setObj4(coluna[6]);
          t.setObj5(coluna[7]);
          t.setObj6(coluna[8]);
          t.setObj7(coluna[9]);
          t.setObj8(coluna[10]);
          t.setObj9(coluna[11]);
          t.setObj10(coluna[12]);
          t.setObj11(coluna[13]);
          t.setObj12(coluna[14]);
          t.setObj13(coluna[15]);
          t.setObj14(coluna[16]);
        }
      }
      catch (Exception ex)
      {
        ex.printStackTrace();
        return false;
      }
      String check = t.getCpu() + "-" + t.getHd();
      check = this.seg.encrypt(check);
      if (check.equalsIgnoreCase(c)) {
        return true;
      }
      return false;
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
    return false;
  }
  
  public int controladora()
    throws IOException
  {
    tijolo t = new tijolo();
    byte[] b = null;
    String g = "";
    String h = "";
    Date DataAtual = new Date();
    Date DataDefinida = new Date();
    try
    {
      b = registra.getComputerIdentifier();
      g = registra.getCPUSerial().replaceAll("-", "&");
      h = registra.getHDSerial("c").replaceAll("-", "b");
    }
    catch (SocketException ex)
    {
      System.out.println("erro ao ler registro!");
    }
    String a = g + "-" + h;
    String c = this.seg.encrypt(a);
    
    String l = "";
    try
    {
      if (!getlicenca().equalsIgnoreCase(""))
      {
        l = getlicenca();
        String[] coluna = l.split("-");
        t.setCpu(coluna[0]);
        t.setHd(coluna[1]);
        t.setData(coluna[2]);
        t.setObj1(coluna[3]);
        t.setObj2(coluna[4]);
        t.setObj3(coluna[5]);
        t.setObj4(coluna[6]);
        t.setObj5(coluna[7]);
        t.setObj6(coluna[8]);
        t.setObj7(coluna[9]);
        t.setObj8(coluna[10]);
        t.setObj9(coluna[11]);
        t.setObj10(coluna[12]);
        t.setObj11(coluna[13]);
        t.setObj12(coluna[14]);
        t.setObj13(coluna[15]);
        t.setObj14(coluna[16]);
      }
      else
      {
        return 2;
      }
    }
    catch (Exception ex)
    {
      System.out.println("erro ao ler licença!");
      
      File arquivo = new File(System.getProperty("user.dir") + "\\\\god.lic");
      
      boolean y = arquivo.delete();
      if (y == true) {
        System.out.println("Licenca invalida deletada");
      } else {
        System.out.println("Licenca invalida nao pode ser deletada remova ela da pasta");
      }
      geraInfo();
    }
    String check = t.getCpu() + "-" + t.getHd();
    
    String checkCripto = this.seg.encrypt(check);
    if (t.getData().toString().equalsIgnoreCase("tijolo"))
    {
      if (checkCripto.equalsIgnoreCase(c))
      {
        if (t.getObj1().equalsIgnoreCase("failover"))
        {
          System.out.println("Licença definitiva com failover!");
          return 3;
        }
        System.out.println("Autenticação definitiva!");
        return 1;
      }
      System.out


package godauthentication;

import exception.BusinessException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Cripto
{
  public static String byteArrayToHexString(byte[] arr)
  {
    StringBuilder ret = new StringBuilder();
    
    byte[] abyte0 = arr;int j = arr.length;
    for (int i = 0; i < j; i++)
    {
      byte val = abyte0[i];
      ret.append(String.format("%02X", new Object[] { Byte.valueOf(val) }));
    }
    return ret.toString();
  }
  
  public static String applySHA1(String valor)
    throws BusinessException
  {
    MessageDigest md;
    try
    {
      md = MessageDigest.getInstance("SHA1");
    }
    catch (NoSuchAlgorithmException e)
    {
      throw new BusinessException("Algoritmo SHA1 nao disponivel: " + e.getMessage());
    }
    md.update(valor.getBytes());
    return byteArrayToHexString(md.digest());
  }
  
  public static String applyMD5(String valor)
    throws BusinessException
  {
    MessageDigest md;
    try
    {
      md = MessageDigest.getInstance("MD5");
    }
    catch (NoSuchAlgorithmException e)
    {
      throw new BusinessException("Algoritmo SHA1 nao disponivel: " + e.getMessage());
    }
    md.update(valor.getBytes());
    return byteArrayToHexString(md.digest());
  }
  
  public static String getSHA1Licence(String valor)
    throws BusinessException
  {
    String hash = applySHA1(valor);
    StringBuilder licence = new StringBuilder();
    for (int i = 0; i < hash.length(); i += 4)
    {
      licence.append(hash.substring(i, i + 4));
      if (i != hash.length() - 4) {
        licence.append("-");
      }
    }
    return licence.toString();
  }
}
Rodrigo

Rodrigo

Responder

Posts

03/01/2017

Rodrigo

Alguém tem ideia?
Responder

Gostei + 0

22/01/2017

Paulo Hendrix

Melhor por MP... E-mail.. Alguém pode ajudar vc por estes meios..
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar