/**
* java.security MessageDigest , , update( )
, digest( ) 。
*/
package org.cric.util;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* MD5
* @author Administrator
*
*/
public class DigestPass {
private MessageDigest messageDigest;
private String result = "";
private byte[] args = null;
public String getDigestPassWord(String userpass) {
try {
// MessageDigest , (MD5)
messageDigest = MessageDigest.getInstance("MD5");
// getBytes( )
messageDigest.update(userpass.getBytes("GBK"));
// MessageDigest digest( ) ,
args = messageDigest.digest();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new RuntimeException();
} catch (UnsupportedEncodingException ee) {
ee.printStackTrace();
throw new RuntimeException();
} finally {
messageDigest.reset();
}
//
result = "";// result , !!!
for (int i = 0; i < args.length; i++) {
result += Integer.toHexString((0x000000ff & args[i]) | 0xffffff00)
.substring(6);
}
return result;
}
}