?? md5.java
字號:
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;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -