谁在说PHP垃圾我跟谁急,看看以下代码谁牛B???
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))
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。