package test;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5 {
public byte[] encrypt(String msg){
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] bt = msg.getBytes();
md5.update(bt);
byte[] rebt = md5.digest();
return rebt;
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static void main(String[] args){
String msg = "我们都是中国人!";
System.out.println("明文是:"+msg);
MD5 md = new MD5();
byte[] retbt = md.encrypt(msg);
String result = new String(retbt);
System.out.println("密文是:"+result);
}
}