Package com. henii. test;
Import java. Security. messagedigest;
/**
* After MD5 encryption, a reversible encryption is performed again.
* The order can be adjusted. You can choose to use Reversible Encryption and then MD5 encryption.
*/
Public class md5andkl {
// MD5 encryption. 32-bit
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 ();
Return S;
}
// Encrypted and decrypted
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 ();
Return K;
}
// Test the main function
Public static void main (string ARGs []) {
String S = new string ("admin ");
System. Out. println ("Original:" + S );
System. Out. println ("after MD5:" + MD5 (s ));
System. Out. println ("MD5 encryption:" + kl (MD5 (s )));
System. Out. println ("decrypted to MD5:" + JM (kl (MD5 (s ))));
}
}