我正在使用md5来保护我的帖子到运行PHP的后端服务器。 参数通过HTTP Post发送。md5与Android和PHP
我有一个问题,如果在其中一个输入参数中有ü,ä或ö,我的md5计算结果在Android和PHP服务器上会有所不同。
在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 "";
}
PHP的服务器上,我只是用
md5() function.
听起来像一个编码问题(ISO-8859-1比如UTF-8)。你使用什么字符集?你能显示一些代码吗? – 2012-01-02 12:22:56
当然,我会编辑我的帖子。 – tobias 2012-01-02 12:25:01
顺便说一句,你可能想要使用SHA1或其他算法来保护你的帖子... MD%不安全了 – 2012-01-02 12:27:12