jfinal 使用类里的方法
package demo; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import com.jfinal.core.Controller; public class HelloController extends Controller { public static byte[] getKeyedDigest(byte[] buffer, byte[] key) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(buffer); return md5.digest(key); } catch (NoSuchAlgorithmException e) { } return null; } public static String getKeyedDigest(String strSrc, String key) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(strSrc.getBytes("UTF8")); String result=""; byte[] temp; temp=md5.digest(key.getBytes("UTF8")); for (int i=0; i<temp.length; i++){ result+=Integer.toHexString((0x000000ff & temp[i]) | 0xffffff00).substring(6); } return result; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); }catch(Exception e) { e.printStackTrace(); } return null; } /** * @param args */ public void index() { String mi; String s = "prodid=8096&agentid=123&backurl=&returntype=2&orderid=agentid1405210000&mobilenum=13811528470&source=esales&mark=&merchantKey=111111"; mi=HelloController.getKeyedDigest(s,""); renderText("mi:"+mi); } }