Java generates MD5 cryptographic string code instance _java

Source: Internet
Author: User
Tags md5 encryption stringbuffer

(1) commonly used in the database will save the user name and password, where the password is not used to save.

Sometimes with MD5 passwords, many languages provide a method or function that converts a string to a MD5 password. The MD5 encryption algorithm is public.

Sometimes you can use your own string encryption algorithm, this encryption algorithm is only to know.

(2) The process of cracking MD5 is to first calculate a lot or all the possible string of MD5 values, after the query can be cracked. Although some sites specify the number of passwords in the 6~20 bit, but to calculate so many in advance is a string and efficient organization of storage, query is still quite cumbersome, rather slow.

Because the number of digits in the MD5 is fixed, such as 16,32,64, and the combination and length of strings are infinite, there is a conflict. But if you know that the length of the string before encryption has a fixed range, such as 6~20, this can still be cracked.

However, if you do not know the length of the character before the encryption then this is endless. It seems that no one can crack it now.

MD5 Password Crack website: can Baidu search "MD5 decryption"

(3) A module program for Java to generate a MD5 password for a given string is given below.

Import Java.security.MessageDigest;
The public class Md5test {public
  
  void toMD5 (String plaintext) {
   try {
    ///Build the MessageDigest object for the specified digest algorithm.
    MessageDigest MD = messagedigest.getinstance ("MD5"); 
    Updates the digest with the specified byte array.
    md.update (Plaintext.getbytes ());
    Hash calculations are done by performing a final operation such as padding.
    byte b[] = Md.digest ();
    Generate a specific MD5 cipher to 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 <)
      Buf.append ("0");
     Buf.append (integer.tohexstring (i));
    }
    System.out.println ("32-bit:" + buf.tostring ());//32-bit encryption
    SYSTEM.OUT.PRINTLN ("16-bit:" + buf.tostring (). substring (8, 24);//16-bit encryption, in fact, is the 32-bit encrypted interception of the Intercept
   } 
   catch (Exception e) {
    e.printstacktrace ();
   }
  }
 
  public static void Main (String agrs[]) {
    new Md5test (). ToMD5 ("LXD");//Encrypt LXD
  }
}

PS: Here again for you to provide 2 MD5 encryption tools, interested friends can refer to:

MD5 Online Encryption Tool:

Http://tools.jb51.net/password/CreateMD5Password

Online md5/hash/sha-1/sha-2/sha-256/sha-512/sha-3/ripemd-160 Encryption Tool:

Http://tools.jb51.net/password/hash_md5_sha

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.