Md5密码破解

    转自http://wenku.baidu.com/link?url=9-2fhVF_2yzq0wvVM5dO-veOfiZtJ7gkkG3o9fTh7JomSpviTb7QKQQ96VK6k5OS_jcKkyReA1rfwP3hVy2t-Ml3YhnEamQPAnexssEcLg3

在网络中MD5是著名的不可逆算法,但是如果知道MD5的加密的字符串则可以通过自己的加密算法对明文进行加密,对加密后的密文与字符串匹配;匹配成功,表示找到明文;但是此程序的时间耗费较高!仅提供一个解密的方法!

public class MD5jiemi {

private static final char code[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
    'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
    'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
    'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
    'U', 'V', 'W', 'X', 'Y', 'Z', ',', '.', '/', ';', '\'', ':', '"',
    '[', ']', '{', '}', '\\', '|', '!', '@', '#', '$', '%', '^', '&',
    '*', '(', ')', '-', '_', '+', '=', '0', '1', '2', '3', '4', '5',
    '6', '7', '8', '9' };

/**
* 六位密码破解
*/
public static void Md5_6(String md5Password) {
   String testPassword;
   MD5 md5Obj = new MD5();
   String result;
   for (int a = 0; a < code.length; a++) {
    testPassword = "";
    testPassword += code[a];
    for (int b = 0; b < code.length; b++) {
     testPassword = testPassword.substring(0, 1);
     testPassword += code[b];
     for (int c = 0; c < code.length; c++) {
      testPassword = testPassword.substring(0, 2);
      testPassword += code[c];
      for (int d = 0; d < code.length; d++) {
       testPassword = testPassword.substring(0, 3);
       testPassword += code[d];
       for (int e = 0; e < code.length; e++) {
        testPassword = testPassword.substring(0, 

4);
        testPassword += code[e];
        for (int f = 0; f < code.length; f++) {
         testPassword = 

testPassword.substring(0, 5);
         testPassword += code[f];
         // System.out.println

(testPassword);
         result = md5Obj.getMD5ofStr

(testPassword);
         if (md5Password.equals(result)) {
          System.out.println("密码

已经破解!");
          System.out.println("明文

是:" + testPassword);
          System.out.println("密文

是:" + md5Password);
          return;
         }
        }
       }
      }
     }
    }
   }
}

/**
* 七位密码破解,写法详见六位密码破解
*/
public static void Md5_7(String md5Password) {
}

/**
* 八位密码破解,写法详见六位密码破解
*/
public static void Md5_8(String md5Password) {
}

public static void main(String[] args) {
   MD5 md5Obj = new MD5();
                // MD5加密对象
   String md5Password = md5Obj.getMD5ofStr(password);
   // 把这个认为我要找到的经过加密的密码
   System.out.println("密码破测试中!");
   System.out.println("明文是:" + password);
   System.out.println("密文是:" + md5Password);
   System.out.println("程序时间计时器!");
   System.out.println("开始时间:" + new Date());
   Md5_6(md5Password);
   // 依次调用6位破解到20位破解..
   // Md5_7(testResult);
   System.out.println("结束时间:" + new Date());
}

private static final String password = "aaa918";

/**
* 这里只是一个实现的方法, 在自己破解的时候把自己的密文直接贴出来, 
* 进行破解, 这里只是进行一个aaaBc8加密的测试
*/
private static final String MD5PWD = "你的数据库中的密文";
}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Java 中,可以使用 MessageDigest 类和字典文件来进行 MD5 的暴力破解。下面是一个简单的示例代码: ```java import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class MD5Cracker { public static void main(String[] args) throws IOException, NoSuchAlgorithmException { String hash = "5f4dcc3b5aa765d61d8327deb882cf99"; // 要破解MD5 值 String dictPath = "/path/to/dictionary/file"; // 字典文件路径 BufferedReader reader = new BufferedReader(new FileReader(dictPath)); String word; while ((word = reader.readLine()) != null) { String hashedWord = getMD5(word); // 对当前单词进行 MD5 加密 if (hashedWord.equals(hash)) { // 比对加密结果与目标 MD5 值是否一致 System.out.println("Found password: " + word); break; } } reader.close(); } public static String getMD5(String input) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(input.getBytes()); byte[] bytes = md.digest(); StringBuilder sb = new StringBuilder(); for (byte b : bytes) { String hex = Integer.toHexString(b & 0xff); if (hex.length() == 1) { sb.append("0"); } sb.append(hex); } return sb.toString(); } } ``` 在上述代码中,我们首先定义了要破解MD5 值和字典文件的路径。然后,我们使用 BufferedReader 读取字典文件中的单词,对每个单词进行 MD5 加密,并与目标 MD5 值进行比对。如果加密结果与目标一致,则说明找到了密码。需要注意的是,由于 MD5 加密是不可逆的,因此我们无法确定破解所需的时间和计算资源,因此此类操作仅限于学术研究或授权测试。在实际应用中,建议使用更加安全的加密算法,如 SHA-256 等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值