MD5加密之Java实现

使用Java实现MD5加密.作为自己的学习备忘.
直接调用EncoderByMd5.getSecretedCode("要加密的字符串");

package org.ec.util;
/**
* @author WEI
*/
import java.security.*;
public class EncoderByMd5 {
private EncoderByMd5() {
}
public static String getSecretedCode(String secretedCode) {
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f' };
try {
byte[] strTemp = secretedCode.getBytes();
MessageDigest mdTemp =
MessageDigest.getInstance("MD5");
mdTemp.update(strTemp);
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) {
System.out.println(e);
return null;
}
}
}

« 阿里妈妈的精明 郁闷死了 »

2条评论 So Far »

  1. mercy :

    Wrote on 2007年09月28日 @ 23:44 pm

    既然加密了,再努把力,用Java写个破解MD5的类吧。

  2. KF.咖啡 :

    Wrote on 2007年09月28日 @ 23:59 pm

    正在考虑中

Comment RSS · TrackBack URI

Leave a Comment

名称: [必填(Required)][让我知道你是谁]

E-mail:[不公开] [必填(Required)][怎样联系你]

网址:[也让我看看你的家]

评论内容: