In the network request I used, MD5 is encrypted, because HTTPS is used, it is true that I don’t know too much.
MD5 is similar
After
package com.xiaohongjiao.cookapp.rsa;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@SuppressWarnings(“unused”)
public class MD5 {
private final static String[] strDigits = { “0”, “1”, “2”, “3”, “4”, “5”,
“6”, “7”, “8”, “9”, “a”, “b”, “c”, “d”, “e”, “f” };
public MD5() {
}
private static String byteToArrayString(byte bByte) {
int iRet = bByte;
// System.out.println(“iRet=”+iRet);
if (iRet < 0) {
iRet += 256;
}
int iD1 = iRet / 16;
int iD2 = iRet % 16;
return strDigits[iD1] + strDigits[iD2];
}
private static String byteToNum(byte bByte) {
int iRet = bByte;
System.out.println(“iRet1=” + iRet);
if (iRet < 0) {
iRet += 256;
}
return String.valueOf(iRet);
}
private static String byteToString(byte[] bByte) {
StringBuffer sBuffer = new StringBuffer();
for (int i = 0; i < bByte.length; i++) {
sBuffer.append(byteToArrayString(bByte[i]));
}
return sBuffer.toString();
}
public static String GetMD5Code(String strObj) {
String resultString = null;
try {
resultString = new String(strObj);
MessageDigest md = MessageDigest.getInstance(“MD5”);
resultString = byteToString(md.digest(strObj.getBytes()));
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
return resultString;
}
public static void main(String[] args) {
MD5 getMD5 = new MD5();
System.out.println(MD5.GetMD5Code(“000000”));
}
}
, some HTTPS head encryption requires 2 “handshake” to establish a connection between the two parties
This is the time stamp
/**
* Time stamp
*
* @return
*/
public static String GetTimestamp() {
return String.valueOf(System.currentTimeMillis());
}
public Map<String, String> getLocation(MainActivity mainActivity) {
return null;
}
Generate 32 -bit random string
/**
* generate 32 as a random string
*
* @return
*/
public static String GetNonceStr() {
String _str = “ABCDEFGHIJKLNMOPQRSTUVWXYZ0123456789abcdefghijklnmopqrstuvwxyz”;
Random random = new Random();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < _str.length(); ++i) {
int number = random.nextInt(32);// [0,62)
sb.append(_str.charAt(number));
}
return sb.toString().toLowerCase();
}
Last request
/** Send token vouchers* /
public static String PostToken(String deviceId, String appVersion,
String systemType, String deviceModel, String deviceName,
int screenWidth, int screenHeight) {
HttpClient httpclient = HttpClientHelper.getNewHttpClient();
HttpPost request = new HttpPost(ParameterConfig.tokenUrl);
// First pack a JSON object
JSONObject param = new JSONObject();
try {
// Lift order combination MD5
String token = “”;
String nonce = GetNonceStr();
String timeStamp = GetTimestamp();
String paramStr = “”;
ArrayList<String> params = new ArrayList<String>();
params.add(token);
params.add(nonce);
params.add(timeStamp);
Collections.sort(params);
for (int i = 0; i < params.size(); i++) {
paramStr += params.get(i);
}
String privataKey = ParameterConfig.privataKey;
paramStr = paramStr + privataKey;
String Signature = MD5.GetMD5Code(paramStr);
request.addHeader(“token”, token);
request.addHeader(“nonce”, nonce);
request.addHeader(“timeStamp”, timeStamp);
request.addHeader(“signature”, Signature);
param.put(“deviceId”, deviceId);
param.put(“appVersion”, appVersion);
param.put(“systemType”, systemType);
param.put(“deviceModel”, deviceModel);
param.put(“deviceName”, deviceName);
param.put(“screenWidth”, screenWidth);
param.put(“screenHeight”, screenHeight);
// Binded to the request Entry
StringEntity se = new StringEntity(param.toString());
request.setEntity(se);
// Send a request
HttpResponse response;
response = httpclient.execute(request);
// Test the status code, if the data is successfully received successfully
int code = response.getStatusLine().getStatusCode();
if (code == 200) {
String rev = EntityUtils.toString(response.getEntity());
// Return to json format: {“ID”: “27jpl ~ j4vsl0lx00E00005”, “Version”: “abc”}
System.out.println(rev + “11111111”);
return rev;
} else {
String rev = EntityUtils.toString(response.getEntity());
System.out.println(rev + “11111111”);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}