md5.java

来自「对于cmpp3.0 开发有一定的帮助,请大家下载下来进行研究.」· Java 代码 · 共 47 行

JAVA
47
字号
package com.zhanghao.common.util;
/**
 * <p>Title: MD5 数据加密</p>
 * <p>Description: 湖南移动短信网关通讯程序</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: sunun tech ltd.</p>
 * @author zhanghao
 * @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;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?