基于mvc的java进销存系统
源代码在线查看: encrypt.java
/*
* Encrypt.java
*
* Created on 2007年5月24日, 下午2:49
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package MD5;
import java.security.MessageDigest;
import java.math.BigInteger;
/**
*
* @author 下雪天
*/
public class Encrypt {
public static String toMD5(String password){
MessageDigest digest;
String algorithm = "MD5";
try{
digest = MessageDigest.getInstance(algorithm);
digest.update(password.getBytes());
return byte2hex(digest.digest());
}catch (Exception e){
e.printStackTrace(System.err);
return null;
}
}
public static String byte2hex(byte[] b){
String result="";
String hex="";
for(int n = 0;n < b.length;n++){
hex=(java.lang.Integer.toHexString(b[n] & 0XFF));
if (hex.length()==1) result=result+"0"+hex;
else result=result+hex;
}
return result.toLowerCase();
}
}