java代码翻译 MD5加密

yklnyc 2018-06-05 11:50:30
public class GetAuthorizationCode
{
public static String getWindowsMACAddress()
{
String mac = null;
BufferedReader bufferedReader = null;
Process process = null;
label129:
try
{
process = Runtime.getRuntime().exec("ipconfig /all");
bufferedReader = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line = null;
int index = -1;
while ((line = bufferedReader.readLine()) != null)
{
index = line.toLowerCase().indexOf("physical address");
if (index >= 0)
{
index = line.indexOf(":");
if (index < 0) {
break;
}
mac = line.substring(index + 1).trim();
break label129;
}
}
}
catch (IOException localIOException1) {}finally
{
try
{
if (bufferedReader != null) {
bufferedReader.close();
}
}
catch (IOException e1)
{
e1.printStackTrace();
}
bufferedReader = null;
process = null;
}
return mac;
}

public static void main(String[] argc)
{
UIManager.put("swing.boldMetal", Boolean.FALSE);
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception localException) {}
String mac = getWindowsMACAddress();
RandomAccessFile rdafile = null;
try
{
rdafile = new RandomAccessFile("authorizationcode.txt", "rw");
mac = StringSecurity.encode(mac, "SHA-1");
mac = StringSecurity.encode(mac, "SHA-256");
rdafile.seek(rdafile.length());
rdafile.writeBytes(mac);
rdafile.seek(rdafile.length());
rdafile.writeBytes("\r\n");
PromptDialog promptdialog = new PromptDialog(new JFrame(), "", true);
promptdialog.setPromptString("", "申请授权成功,请将授权码文件发给作者,等待批准授权!", "", "授权");
promptdialog.setVisible(true);
rdafile.close();
System.exit(0);
}
catch (Exception localException1) {}finally
{
try
{
rdafile.close();
System.exit(0);
}
catch (Exception localException2) {}
}
}
}

public class SetAuthorizationCode
{
public static void main(String[] argc)
{
UIManager.put("swing.boldMetal", Boolean.FALSE);
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception localException) {}
RandomAccessFile rdafileone = null;
RandomAccessFile rdafiletwo = null;
String stroriginaltext = "";
String strsecrettext = "";
try
{
File file = new File("authorizationcode.txt");
if (file.exists())
{
rdafileone = new RandomAccessFile("authorizationcode.txt", "rw");
rdafiletwo = new RandomAccessFile("legalauthorizationcode.key", "rw");
while ((stroriginaltext = rdafileone.readLine()) != null) {
if (!stroriginaltext.equals(""))
{
strsecrettext = StringSecurity.encode(stroriginaltext);
strsecrettext = StringSecurity.encode(strsecrettext);
rdafiletwo.writeBytes(strsecrettext + "\r\n");
}
}
PromptDialog promptdialog = new PromptDialog(new JFrame(), "", true);
promptdialog.setPromptString("", "成功批准授权!", "", "批准授权");
promptdialog.setVisible(true);
rdafileone.close();
rdafiletwo.close();
}
else
{
PromptDialog promptdialog = new PromptDialog(new JFrame(), "", true);
promptdialog.setPromptString("", "批准授权失败!", "", "批准授权");
promptdialog.setVisible(true);
}
System.exit(0);
}
catch (Exception localException1) {}finally
{
try
{
rdafileone.close();
rdafiletwo.close();
System.exit(0);
}
catch (Exception localException2) {}
}
}
}

public class StringSecurity
{
private static final String[] hexDigits = { "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
public static final String MD5 = "MD5";
public static final String SHA1 = "SHA-1";
public static final String SHA256 = "SHA-256";

private static String byteArrayToHexString(byte[] b)
{
StringBuffer resultSb = new StringBuffer();
for (int i = 0; i < b.length; i++) {
resultSb.append(byteToHexString(b[i]));
}
return resultSb.toString();
}

private static String byteToHexString(byte b)
{
int n = b;
if (n < 0) {
n += 256;
}
int d1 = n / 16;
int d2 = n % 16;
return hexDigits[d1] + hexDigits[d2];
}

public static String encode(String data)
{
String resultString = null;
try
{
resultString = new String(data);
MessageDigest md = MessageDigest.getInstance("MD5");
resultString = byteArrayToHexString(md.digest(
resultString.getBytes()));
}
catch (Exception ex)
{
ex.printStackTrace();
}
return resultString.toUpperCase();
}

public static String encode(String data, String encType)
{
String resultString = null;
try
{
resultString = new String(data);
MessageDigest md = MessageDigest.getInstance(encType);
resultString = byteArrayToHexString(md.digest(
resultString.getBytes()));
}
catch (Exception ex)
{
ex.printStackTrace();
}
return resultString.toUpperCase();
}
}


是获取本机物理地址 加密吗? 用的什么加密算法~~
然后怎么才能登陆呢

源文件
https://pan.baidu.com/s/1K9-j9fE5ToNAK3lXF9-CUA


...全文
785 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjsl__ 2018-06-06
  • 打赏
  • 举报
回复
申请授权,系统安装,考试 不行吗?
yjsl__ 2018-06-06
  • 打赏
  • 举报
回复
mac = StringSecurity.encode(mac, "SHA-1"); mac = StringSecurity.encode(mac, "SHA-256"); 获取本机物理地址,用SHA-1算法加密得到密文A,再用SHA-256算法加密A得到密文 然后怎么才能登陆呢?需要SystemLogin.class的源码
yklnyc 2018-06-06
  • 打赏
  • 举报
回复
引用 1 楼 yjsl__ 的回复:
mac = StringSecurity.encode(mac, "SHA-1"); mac = StringSecurity.encode(mac, "SHA-256"); 获取本机物理地址,用SHA-1算法加密得到密文A,再用SHA-256算法加密A得到密文 然后怎么才能登陆呢?需要SystemLogin.class的源码
  public void actionPerformed(ActionEvent e)
  {
    if (e.getSource() == this.jbtnquit)
    {
      System.exit(0);
    }
    else if (this.vectorseriescode.contains(this.jtfdseriescode.getText().trim()))
    {
      writeKey();
      readSeriesCode();
      if (this.flag)
      {
        this.jlblclue.setForeground(Color.black);
        this.jlblclue.setText("系统安装成功!");
      }
      else
      {
        this.jlblclue.setForeground(Color.red);
        this.jlblclue.setText("系统已经安装!");
      }
    }
    else
    {
      this.jlblclue.setForeground(Color.red);
      this.jlblclue.setText("序列号错误,请与作者联系!");
    }
  }
  
  public void readSeriesCode()
  {
    Connection con = null;
    Statement sql = null;
    
    this.vectorseriescode.removeAllElements();
    this.vectoroldauthorization.removeAllElements();
    ResultSet rs;
    try
    {
      String strurl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=examdatadb.mdb";
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con = DriverManager.getConnection(strurl, "xjj308B", "xjj308B");
      sql = con.createStatement();
      ResultSet rs = sql.executeQuery("select * from seriescode");
      while (rs.next()) {
        this.vectorseriescode.add(rs.getString("序列号"));
      }
      rs = sql.executeQuery("select * from authorizationcode");
      while (rs.next()) {
        this.vectoroldauthorization.add(rs.getString("标识"));
      }
    }
    catch (Exception e)
    {
      setVisible(false);
      new AbendImage(new JFrame());
      try
      {
        Thread.sleep(5000L);
      }
      catch (Exception localException1) {}
      System.exit(0);
    }
    finally
    {
      try
      {
        sql.close();
        con.close();
      }
      catch (Exception localException2) {}
    }
  }
  
  public void writeKey()
  {
    this.flag = false;
    Connection con = null;
    Statement sql = null;
    try
    {
      File file = new File("legalauthorizationcode.key");
      FileReader inone = new FileReader(file);
      BufferedReader intwo = new BufferedReader(inone);
      Vector<String> vectorauthorization = new Vector();
      String strkey = "";
      while ((strkey = intwo.readLine()) != null) {
        if (!strkey.equals("")) {
          vectorauthorization.add(strkey);
        }
      }
      String strurl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=examdatadb.mdb";
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con = DriverManager.getConnection(strurl, "xjj308B", "xjj308B");
      sql = con.createStatement();
      for (int i = 0; i < vectorauthorization.size(); i++) {
        if (!this.vectoroldauthorization.contains(vectorauthorization.get(i)))
        {
          String stradd = "insert into authorizationcode values('" + ((String)vectorauthorization.get(i)).toString() + "')";
          sql.executeUpdate(stradd);
          this.flag = true;
        }
      }
      inone.close();
      intwo.close();
    }
    catch (Exception e)
    {
      setVisible(false);
      PromptDialog promptdialog = new PromptDialog(new JFrame(), "", true);
      promptdialog.setPromptString("", "安装失败,请与作者联系!", "", "系统安装");
      promptdialog.setVisible(true);
      System.exit(0);

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧