0
如何將此Java代碼轉換爲PHP?如何將java中的字節MD5轉換爲php
public static String encryptMD5_Salt(String content) {
String resultString = "";
String appkey = "acdf,kef";
byte[] a = appkey.getBytes();
byte[] datSource = content.getBytes();
byte[] b = new byte[a.length + 4 + datSource.length];
int i;
for (i = 0; i < datSource.length; i++) {
b[i] = datSource[i];
}
b[i++] = (byte) 143;
b[i++] = (byte) 112;
b[i++] = (byte) 131;
b[i++] = (byte) 143;
for (int k = 0; k < a.length; k++) {
b[i] = a[k];
i++;
}
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(b);
resultString = new HexBinaryAdapter().marshal(md5.digest());
} catch (Exception e) {
e.printStackTrace();
}
return resultString.toLowerCase();
}
的問題是,我無法找到Integer
轉換爲byte
Java中的等價方式:
b[i++] = (byte) 143;
b[i++] = (byte) 112;
b[i++] = (byte) 131;
b[i++] = (byte) 143;
的PHP代碼:
$hexString = '123456';#sample value
$bkey = pack('a*',$hexString);
$bkey .= pack('N*',143,112,131,143);
$bkey = pack('a*','acdf,kef');
$re = md5($bkey);
$re =sha1('sha256',$re);
,他們得到的結果差異。
以及如何在php中使用md5與字節? – brook