java md5在线解密免费_Java MD5如何解密?

2014-08-23 回答

package endecrypt;

import java.io.unsupportedencodingexception;

import java.security.messagedigest;

import java.security.nosuchalgorithmexception;

/**

* 采用md5加密解密

* @author tfq

* @datetime 2011-10-13

*/

public class md5util {

/***

* md5加码 生成32位md5码

*/

public static string string2md5(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();

}

/**

* 加密解密算法 执行一次加密,两次解密

*/

public static string convertmd5(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;

}

// 测试主函数

public static void main(string args[]) {

string s = new string("tangfuqiang");

system.out.println("原始:" + s);

system.out.println("md5后:" + string2md5(s));

system.out.println("加密的:" + convertmd5(s));

system.out.println("解密的:" + convertmd5(convertmd5(s)));

}

}

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页