[英]md5 with Android and PHP
I am using an md5 to secure my posts to a backendserver running PHP. 我使用md5来保护我的帖子到运行PHP的后端服务器。 The parameters are send via HTTP Post. 参数通过HTTP Post发送。
I have one problem, the result of my md5 calculation is different on Android and the PHP server if there is a ü, ä or ö in one of the input parameters. 我有一个问题,我的md5计算结果在Android和PHP服务器上是不同的,如果其中一个输入参数中有ü,ä或ö。
On Android, the hash is calculated via this function: 在Android上,哈希是通过此函数计算的:
public static final String md5(final String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest
.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
String h = Integer.toHexString(0xFF & messageDigest[i]);
while (h.length() < 2)
h = "0" + h;
hexString.append(h);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
on the PHP server I simply use 在我只是使用的PHP服务器上
md5() function.
看起来你需要在PHP中将utf-8编码的字符串传递给md5
:
md5(utf8_encode($string));
It could be that you are using the platform's default charset. 可能是您正在使用平台的默认字符集。
Instead, try: 相反,尝试:
digest.update(s.getBytes("UTF-8");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.