Java generates an instance of the MD5 encrypted string code

  • 2020-04-01 03:56:04
  • OfStack

          (1) generally, the user name and password will be saved in the database, and the password is not saved in plain code.

      Sometimes with MD5 passwords, many languages provide methods or functions for generating strings into MD5 passwords. The MD5 encryption algorithm is public.

      Sometimes you can use your own string encryption algorithm, which only you know.

(2) the process of cracking MD5 is to calculate a large number of or all the possible strings of the MD5 value, after the query can be cracked. Although some sites specify passwords in the range of 6 to 20 digits, it can be cumbersome and slow to calculate that many strings in advance and organize storage and queries effectively.

Since the MD5 bits are fixed, such as 16,32,64, and the combinations of strings and lengths are infinite, there is a conflict. However, if you know that the length of the string before encryption is fixed, such as 6 to 20, this can be cracked.

However, if you don't know the length of the character before the encryption then this is infinite. No one seems to have cracked it yet.

        MD5 password cracking website: can baidu search "(link: https://www.baidu.com/s? Ie = utf-8 & f = 3 & rsv_bp = 0 & rsv_idx = 1 & tn = baidu&wd = md5 & rsv_pq = 968 dc5000003dc6b & rsv_t = 38 ccwr6lpy % 2 fjvyykuwqrmsgyzjx1g5hvq % 2 fpe9gjaqootevh6gw8ypxmrmkg & rsv_enter = 1 & 2 & rsv_sug1 rsv_sug3 = = 2 & oq = MD&rsv _sug2 = 0 & RSP = 0 & I NputT = 2594 & rsv_sug4 = 2594)."

(3) below is a Java module that generates the MD5 password for a given string.


import java.security.MessageDigest;
public class Md5Test {
  
  public void toMD5(String plainText) {
   try {
    //Generate the MessageDigest object that implements the specified digest algorithm.
    MessageDigest md = MessageDigest.getInstance("MD5"); 
    //Updates the digest with the specified byte array.
    md.update(plainText.getBytes());
    //Hash calculations are completed by performing final operations such as population.
    byte b[] = md.digest();
    //Generate the concrete md5 password into the buf array
    int i;
    StringBuffer buf = new StringBuffer("");
    for (int offset = 0; offset < b.length; offset++) {
     i = b[offset];
     if (i < 0)
      i += 256;
     if (i < 16)
      buf.append("0");
     buf.append(Integer.toHexString(i));
    }
    System.out.println("32 position : " + buf.toString());//32-bit encryption
    System.out.println("16 position : " + buf.toString().substring(8, 24));//16-bit encryption, in fact, is the interception of 32-bit encryption
   } 
   catch (Exception e) {
    e.printStackTrace();
   }
  }
 
  public static void main(String agrs[]) {
    new Md5Test().toMD5("LXD");//Encryption LXD
  }
}

PS: here to provide you with 2 MD5 encryption tools, interested friends can refer to:

MD5 online encryption tool:

(link: http://tools.jb51.net/password/CreateMD5Password)

Online MD5/hash/ sha-1 / sha-2 / sha-256 / sha-512 / sha-3 / ripemd-160 encryption tools:

(link: http://tools.jb51.net/password/hash_md5_sha)


Related articles: