首頁  >  文章  >  後端開發  >  谁在说PHP垃圾我跟谁看看以下代码谁牛B?

谁在说PHP垃圾我跟谁看看以下代码谁牛B?

WBOY
WBOY原創
2016-06-21 08:45:32832瀏覽

Java代码

public static String getMD5(String orgin, String charset) {	if (charset == null) charset = "utf-8";	String result = null;	try {		MessageDigest md = MessageDigest.getInstance("MD5");		result = byte2hex(md.digest(orgin.getBytes(charset)));	} catch (Exception e) {		throw new java.lang.RuntimeException("sign error !", e);	}	return result;}private static String byte2hex(byte[] b){	StringBuffer hs = new StringBuffer(); 	String stmp = ""; 	for (int n = 0; n < b.length; n++) { 		 stmp = (java.lang.Integer.toHexString(b[n] & 0XFF)); 		 if (stmp.length() == 1) 		 hs.append("0").append(stmp); 		 else 		 hs.append(stmp); 	 } 	 return hs.toString();}public static String encode(byte[] srcContent) {	if(srcContent == null) {		return null;	}	//的实现会每76个字符后面增加一个回车,需要删除。	return new BASE64Encoder().encode(srcContent).replace("\r\n", "");}String data = "helloword";String secret = "123456";String md5Value = Md5Util.getMD5(data + secret);String reSign = Base64Util.encode(md5Value.getBytes("utf-8")); //结果reSign=Y2UyMTllODgzNTVmMmYzYzI3NTEwOWM0OWY1YTVmMjU=

PHP代码

$reSign = base64_encode(md5($data.$secret))
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn