问题:提示The constructor String(byte[], int, int, int) is deprecated的警告,原因是些函数已过时,查询了JDK文档,解释为" 已过时。 该方法无法将字节正确地转换为字符。从 JDK 1.1 开始,完成该转换的首选方法是使用带有 Charset、字符集名称,或使用平台默认字符集的 String 构造方法。"我要怎么修改才没有提示。代码如下
package com.pansonlu.common.util;
/**
* <p>Title: MD5 数据加密</p>
* <p>Description: 湖南移动短信网关通讯程序</p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: Sunrise tech ltd.</p>
* @author pansonlu
* @version 1.0
*/
/**
* 使用说明
* 1. AuthenticatorICP = MD5(Source_Addr+ 36(\0) + shared secret ) ;
* 2. AuthenticatorISMG = MD5(Status+AuthenticatorICP+Tls_available+shared secret);
**/import java.security.*;public class MD5 { private static MessageDigest alg ;
public MD5() {
try{
alg = MessageDigest.getInstance("MD5");
}
catch(NoSuchAlgorithmException e){
System.out.println("MD5 has error="+e);
}
} // 传入要加密的字符串,此函数反回此串的16个字节的摘要密码字符串
public static String encrypt(String key){
String m = key ;
return computeDigest(m.getBytes()) ;
} private static String computeDigest(byte[] b){
alg.reset();
alg.update(b);
byte[] hash = alg.digest(); //得到摘要
//String d = hash.toString();
String d = new String(hash, 0, 0, hash.length);
System.out.println(d);
return d;
}
}这句代码出警告。“String d = new String(hash, 0, 0, hash.length);”
package com.pansonlu.common.util;
/**
* <p>Title: MD5 数据加密</p>
* <p>Description: 湖南移动短信网关通讯程序</p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: Sunrise tech ltd.</p>
* @author pansonlu
* @version 1.0
*/
/**
* 使用说明
* 1. AuthenticatorICP = MD5(Source_Addr+ 36(\0) + shared secret ) ;
* 2. AuthenticatorISMG = MD5(Status+AuthenticatorICP+Tls_available+shared secret);
**/import java.security.*;public class MD5 { private static MessageDigest alg ;
public MD5() {
try{
alg = MessageDigest.getInstance("MD5");
}
catch(NoSuchAlgorithmException e){
System.out.println("MD5 has error="+e);
}
} // 传入要加密的字符串,此函数反回此串的16个字节的摘要密码字符串
public static String encrypt(String key){
String m = key ;
return computeDigest(m.getBytes()) ;
} private static String computeDigest(byte[] b){
alg.reset();
alg.update(b);
byte[] hash = alg.digest(); //得到摘要
//String d = hash.toString();
String d = new String(hash, 0, 0, hash.length);
System.out.println(d);
return d;
}
}这句代码出警告。“String d = new String(hash, 0, 0, hash.length);”
int hibyte,
int offset,
int count)
构造函数已过时,就是说不建议使用了这样改一下 private static String computeDigest(byte[] b){
alg.reset();
alg.update(b);
byte[] hash = alg.digest(); //得到摘要
//String d = hash.toString();
String d = new String(hash);
System.out.println(d);
return d;
}就不会有问题了