H5 the MD5 encryption and decryption class of Java for chess source lease

Source: Internet
Author: User
Tags gz file md5 encryption

Understanding MD5
MD5 application is very extensive H5 chess source rental (h5.hxforum.com) Contact 170618633533 Penguin 2952777280 (http://yhgj8004.com) source Sale Room Card Sale backstage rental contact only Penguin. For example, when we download some kind of software in Unix, we often see a file with a. md5 extension, which is about:
MD5 (tanajiya.tar.gz) = 0ca175b9c0f726a831d895e269332461
This is the digital signature of the tanajiya.tar.gz file. So when we get this file, we use the tool to calculate the MD5 value of the file, and then compare it with the values recorded in the. MD5 recorded in the file, and if not, you know that the contents of the file have changed.
The MD5 algorithm, which treats the entire file as a large text message, generates this unique MD5 message digest through its irreversible string transform algorithm. This is equivalent to the fingerprint of this file, and if anyone modifies the contents of the file or downloads the file because the network problem is incomplete, the resulting MD5 value is also changed.
The MD5 algorithm is essentially a hashing algorithm, so the MD5 value is a hash value. Some of the features of MD5 can be learned from this example:
1, for the same file, the calculated MD5 value is always the same. There are no random numbers or uncertainties in the MD5 algorithm.
The 2,MD5 algorithm is public. So we can find a lot of MD5 generators, but the algorithm behind them is the same.
3, we can assume that the world's files are infinite, and the resulting MD5 value is always a 128-bit binary number. therefore is an infinite sequence to a finite sequence of mappings. It can be learned that the MD5 algorithm is irreversible, that is, we can not use a MD5 value to derive the content of the source file.
4, from the infinite sequence to the finite sequence of mappings this can be inferred that the MD5 algorithm may be conflicting (this is the problem that all hash functions will encounter). That is, two different files may produce the same MD5 value. We know that the 2^128 is a huge number, so it is a reliable algorithm to think that the MD5 conflict is theoretically present and the probability of real life is very low. However, the collision algorithm developed in recent years makes the computer can draw a possible conflict value in a short time, which is the flaw of MD5 algorithm. We will refer to the harm of this defect later.
Other applications of MD5
Digital certificates
As in the previous example, a MD5 certificate is included when the software is released. If there is a third-party certification body, with MD5 can also prevent the file author's "Repudiation", which is called Digital signature application.
Security Certifications
MD5 is also widely used in operating system login authentication, such as UNIX, all kinds of BSD system login password, digital signature and many other aspects. As in the Unⅸ system, the user's password is MD5 (or other similar algorithm) is stored in the file system after the hash operation. When the user logs in, the system MD5 the user's password into a hash, and then compares the MD5 value stored in the file system to determine if the password was entered correctly. Through such steps, the system can determine the legality of the user login system without knowing the user's password. This avoids the user's password being known to users who have system administrator privileges. If the user loses the password, only the administrator can reset the password.

MD5 's flaws
The previously mentioned MD5 algorithm, also known as collision algorithm. The essence is that for a given MD5, the possible source file content can be found in a very short period of time. The above mentioned MD5 algorithm is irreversible, that is, the algorithm can not guarantee that the source file content, but can ensure that the file content calculated MD5 value must be the same as the source file generated MD5. Let's see what the harm is: for example, the user login password is 666666, the background database is stored MD5 value, if it is 0ca175b9c0f726a831d895e269332461. Cracked the person to get this MD5 value, use the crack algorithm to calculate and this MD5 collision password, if it is 678865.
So the person can use 678865 to log in, because the output of MD5 or 0ca175b9c0f726a831d895e269332461, so this person can log on smoothly.
An easy solution to this problem is to copy the initial password entered by the user into 666666666666, then generate the MD5 and deposit it into the database. The potential password for the hack algorithm is no longer 678865, and he cannot log in with the possible password.
In addition to the collision algorithm hack, now the most used by hackers to decipher the password method is known as a "running dictionary" of Brute Force Method (brute). There are two ways to get a dictionary, one is the daily collection of strings used for the password table, and the other is generated by the arrangement of the combination of methods, the first use MD5 program to calculate the MD5 value of these dictionary items, and then use the target MD5 value in the dictionary to retrieve. We assume that the maximum length of the password is 8 bytes (8 Bytes), and that the password can only be letters and numbers, a total of 26+26+10=62 characters, and the number of items in the sorted dictionary is P (62,1) +p (62,2) .... +p (62,8), which is already a very astronomical figure, Storing this dictionary requires a terabytes of disk array, and there is a premise that it is possible to obtain the password MD5 value of the target account. This encryption technique is widely used in Unⅸ systems, which is one of the important reasons why the Unⅸ system is more robust than the general operating system.

Simple MD5 Class
[Java] View plain copy
Import Java.security.MessageDigest;

public class Md5demo {

public static class  MD5_test {    
      public   final   static  String MD5(String s) {    
       char  hexDigits[] = {  ‘0‘ ,  ‘1‘ ,  ‘2‘ ,  ‘3‘ ,  ‘4‘ ,  ‘5‘ ,  ‘6‘ ,  ‘7‘ ,  ‘8‘ ,  ‘9‘ ,    
         ‘a‘ ,  ‘b‘ ,  ‘c‘ ,  ‘d‘ ,  ‘e‘ ,  ‘f‘  };    
       try  {    
        byte [] strTemp = s.getBytes();    
        MessageDigest mdTemp = MessageDigest.getInstance("MD5" );    
        byte [] md = mdTemp.digest();    
        int  j = md.length;    
        char  str[] =  new   char [j *  2 ];    
        int  k =  0 ;    
        for  ( int  i =  0 ; i < j; i++) {    
         byte  byte0 = md[i];    
         str[k++] = hexDigits[byte0 >>> 4  &  0xf ];    
         str[k++] = hexDigits[byte0 & 0xf ];    
        return   new  String(str);    
       } catch  (Exception e) {    
        return   null ;    

      public   static   void  main(String[] args) {

Md5_test AA = new Md5_test ();
System.out.print (md5_test. MD5 ("B"));

Encrypting----------Decrypting MD5 class
[Java] View plain copy
Import Java.security.MessageDigest;

public class Md5andkl {
MD5 overweight. 32 Guests
public static string MD5 (String inStr) {
MessageDigest MD5 = NULL;
try {
MD5 = messagedigest.getinstance ("MD5");
} catch (Exception e) {
System.out.println (E.tostring ());
E.printstacktrace ();
Return "";
char[] Chararray = Instr.tochararray ();
byte[] ByteArray = new Byte[chararray.length];

for (int i = 0; i < chararray.length; i++)
Bytearray[i] = (byte) chararray[i];

byte[] md5bytes = Md5.digest (ByteArray);

StringBuffer hexvalue = new StringBuffer ();

for (int i = 0; i < md5bytes.length; i++) {
int val = ((int) md5bytes[i]) & 0xFF;
if (Val < 16)
Hexvalue.append ("0");
Hexvalue.append (Integer.tohexstring (Val));

return hexvalue.tostring ();

Reversible encryption algorithm
public static string KL (String inStr) {
string s = new string (INSTR);
Char[] A = Instr.tochararray ();
for (int i = 0; i < a.length; i++) {
A[i] = (char) (a[i] ^ ' t ');
string s = new String (a);
return s;

Decryption after encryption
public static string JM (String inStr) {
Char[] A = Instr.tochararray ();
for (int i = 0; i < a.length; i++) {
A[i] = (char) (a[i] ^ ' t ');
String k = new String (a);
return k;

Test the main function
public static void Main (String args[]) {
string s = new String ("a");
System.out.println ("Original:" + s);
System.out.println ("After MD5:" + MD5 (s));
System.out.println ("MD5 after re-encryption:" + KL (MD5 (s));
System.out.println ("Decrypted for MD5:" + JM (KL (MD5 (s)));

H5 the MD5 encryption and decryption class of Java for chess source lease

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.