提示这个警告,The constructor String(byte[], int, int, int) is deprecated,请问要怎么改,我是刚接触JAVA的菜鸟。
查询了JDK文档,说是用ChartSet,警告代码“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);
    return d;
  }
}