0
在我的Android應用程序中,我使用MD5散列鍵來保證數據訪問的安全性。我使用電子郵件+時間+「後綴」字符串來生成密鑰。它運作良好。但問題是,當我使用至少有一個加號(+
)的電子郵件地址(例如[email protected]
)時,服務器正在返回「不正確的訪問密鑰」消息。我注意到它正在使用減號(-
),下劃線(_
)等簽名的電子郵件地址,但它不適用於具有加號(+
)符號的電子郵件地址。我生成MD5哈希鍵使用這種方法:爲什麼MD5哈希鍵與php生成的MD5哈希鍵不匹配?
public static String MD5_Hash(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 "";
}
什麼是源? md.update(來源)?? – TKumar 2012-07-24 10:51:13