您的位置:首页 > 运维架构 > Apache

使用Apache digest做md5加密的范例

2009-01-15 13:27 726 查看
活用Apache commons,使用Apache digest做md5加密的范例。

import java.security.NoSuchAlgorithmException;
import org.apache.commons.codec.digest.DigestUtils;
/**
* @author loveapple
* @since 2009-01-15
* @version $Revision$
*/
public class MD5Test {
//加密后的文字串
static final String CHANGEME_MD5_STR = "4cb9c8a8048fd02294477fcb1a41191a";
//被加密的文字串
static final String TARGET = "changeme";

public static void main(String[] argvs){
try {
MessageDigestAdapter adapter = new MessageDigestAdapter("MD5");
String md5str = adapter.digest(TARGET);
System.out.println(md5str);

if(CHANGEME_MD5_STR.equals(md5str)){
System.out.println(md5str + "->" + CHANGEME_MD5_STR);
System.out.println("same with mysql request. length is [" + md5str.length() + "]");

}else{
System.out.println("NOT SAME! with mysql requse");
}

System.out.println("common codec result: " + DigestUtils.md5Hex(TARGET));
if(CHANGEME_MD5_STR.equals(DigestUtils.md5Hex(TARGET))){
System.out.println("code result same with mysql request too. length is [" + DigestUtils.md5Hex(TARGET) + "]");
}

}catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}

}
}


 

<script type="text/javascript"><!--
google_ad_client = "pub-2097865745512830";
/* 728x90, 作成済み 08/12/22 */
google_ad_slot = "5461334436";
google_ad_width = 728;
google_ad_height = 90;
// --></script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

转贴请注明出处:http://blog.csdn.net/froole

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息