猿问

如何为我对 PHP 的 Android 请求添加 md5 校验和

所以,我有一个 Android 应用程序,我需要验证对我的服务器发出的所有请求。有人可以解释或告诉我如何在 Android 中制作和发送请求的校验和并在 PHP 中进行验证吗?


隔江千里
浏览 173回答 1
1回答

白板的微信

您可以在 android 端使用以下代码加密您对 md5 的请求public static final String md5(final String s) {final String MD5 = "MD5";try {&nbsp; &nbsp; // Create MD5 Hash&nbsp; &nbsp; MessageDigest digest = java.security.MessageDigest&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .getInstance(MD5);&nbsp; &nbsp; digest.update(s.getBytes());&nbsp; &nbsp; byte messageDigest[] = digest.digest();&nbsp; &nbsp; // Create Hex String&nbsp; &nbsp; StringBuilder hexString = new StringBuilder();&nbsp; &nbsp; for (byte aMessageDigest : messageDigest) {&nbsp; &nbsp; &nbsp; &nbsp; String h = Integer.toHexString(0xFF & aMessageDigest);&nbsp; &nbsp; &nbsp; &nbsp; while (h.length() < 2)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h = "0" + h;&nbsp; &nbsp; &nbsp; &nbsp; hexString.append(h);&nbsp; &nbsp; }&nbsp; &nbsp; return hexString.toString();} catch (NoSuchAlgorithmException e) {&nbsp; &nbsp; e.printStackTrace();}return "";}在 php 方面相同,您必须使用 md5 解密相同的请求才能使用
随时随地看视频慕课网APP
我要回答