md5加密的import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;public class MD5 {
public static String getMd5(String str) {
// //////////////////////////////////////////////////
// String
MessageDigest md;
// System.out.println(MD5.MD5Encode("11"));
// 生成一个MD5加密计算摘要
try {
md = MessageDigest.getInstance("MD5"); // 计算md5函数
md.update(str.getBytes());
// digest()最后确定返回md5 hash值,返回值为8为字符串。因为md5 hash值是16位的hex值,实际上就是8位的字符
// BigInteger函数则将8位的字符串转换成16位hex值,用字符串来表示;得到字符串形式的hash值
String pwd = new BigInteger(1, md.digest()).toString(16);
//System.out.println(pwd); // hex_hmac_md5
/*
* if ("".equals(pwd)) { return true; } else { return false; }
*/
return pwd;
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} // ////////////////////////////////////////
}
}
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;public class MD5 {
public static String getMd5(String str) {
// //////////////////////////////////////////////////
// String
MessageDigest md;
// System.out.println(MD5.MD5Encode("11"));
// 生成一个MD5加密计算摘要
try {
md = MessageDigest.getInstance("MD5"); // 计算md5函数
md.update(str.getBytes());
// digest()最后确定返回md5 hash值,返回值为8为字符串。因为md5 hash值是16位的hex值,实际上就是8位的字符
// BigInteger函数则将8位的字符串转换成16位hex值,用字符串来表示;得到字符串形式的hash值
String pwd = new BigInteger(1, md.digest()).toString(16);
//System.out.println(pwd); // hex_hmac_md5
/*
* if ("".equals(pwd)) { return true; } else { return false; }
*/
return pwd;
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} // ////////////////////////////////////////
}
}
解决方案 »
- js 关于encodeURI编码问题,急!(有用到JQuery做ajax处理,程序是java开发的)
- IE浏览器是以什么编码方式发送数据给服务端
- 请大家帮我看看这个Spring配置文件
- 关于<html:base />的位置问题
- 我的checkbox值怎么取不到!!!!!急,在线等待
- 关于路径的简单问题
- 关于数据库写数据的BEAN 不知道为什么写不进去数据 在线等
- 怎么转换时间格式?在线等待
- 如何做到地址连接拦截
- 对方提供的webservice参数类型为type="tns:ArrayOfString",我该传递什么类型的数据呢?
- 关于java动态特性的问题,怎样调用未知类的未知方法?
- 一个表格格式的问题。
import java.util.Date;public class DateUtil {
public static String formatHHmm(Date date){
String rev = "";
SimpleDateFormat df=null;
try{
df = new SimpleDateFormat("HH:mm");
rev = df.format(date);
}catch(Exception e){
}finally{
df = null;
}
return rev;
}
public static String formatyyyyMMdd(Date date){
String rev = "";
SimpleDateFormat df=null;
try{
df = new SimpleDateFormat("yyyy-MM-dd");
rev = df.format(date);
}catch(Exception e){
}finally{
df = null;
}
return rev;
}
public static Date formatyyyyMMdd(String date){
SimpleDateFormat df=null;
try{
df = new SimpleDateFormat("yyyy-MM-dd");
return df.parse(date);
}catch(Exception e){
return null;
}finally{
df = null;
}
}
public static String formatyyyyMMddHHmm(Date date){
String rev = "";
SimpleDateFormat df=null;
try{
df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
rev = df.format(date);
}catch(Exception e){
}finally{
df = null;
}
return rev;
}
public static Date formatyyyyMMddHHmm(String date){
SimpleDateFormat df=null;
try{
df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return df.parse(date);
}catch(Exception e){
return null;
}finally{
df = null;
}
}
public static String formatyyyyMMddHHmmss(Date date){
String rev = "";
SimpleDateFormat df=null;
try{
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
rev = df.format(date);
}catch(Exception e){
}finally{
df = null;
}
return rev;
}
public static Date formatyyyyMMddHHmmss(String date){
SimpleDateFormat df=null;
try{
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return df.parse(date);
}catch(Exception e){
return null;
}finally{
df = null;
}
}
}