我正在使用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