jdnbjcc 2021-06-16 09:29 采纳率: 0%
浏览 17

请问各位大佬们 这个安卓应用 java的sign加密算法是怎么实现的 过程是怎样的


package com.qsmx.qigyou.ec.httputil;

import android.text.TextUtils;
import com.qsmx.qigyou.app.Atmos;
import com.qsmx.qigyou.ec.util.ApkUtil;
import com.qsmx.qigyou.ec.util.Md5Util;
import com.qsmx.qigyou.manager.ApkManager;
import com.qsmx.qigyou.util.storage.AtmosPreference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.WeakHashMap;

public class BaseRequestWrapper {
    private WeakHashMap<String, Object> map = new WeakHashMap();

    public WeakHashMap<String, Object> sign() {
        ArrayList arrayList = new ArrayList();
        for (String add : this.map.keySet()) {
            arrayList.add(add);
        }
        String[] strArr = (String[]) arrayList.toArray(new String[arrayList.size()]);
        Arrays.sort(strArr);
        String str = "eaM3N_sUOqQn,A,q";
        for (Object obj : strArr) {
            if (!TextUtils.isEmpty((CharSequence) this.map.get(obj))) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(str);
                stringBuilder.append(obj);
                stringBuilder.append(this.map.get(obj));
                str = stringBuilder.toString();
            }
        }
        StringBuilder stringBuilder2 = new StringBuilder();
        stringBuilder2.append(str);
        stringBuilder2.append("eaM3N_sUOqQn,A,q");
        try {
            this.map.put("sign", Md5Util.md5(stringBuilder2.toString()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this.map;
    }

    public BaseRequestWrapper() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(ApkManager.getVersionCode(Atmos.getApplicationContext()));
        stringBuilder.append("");
        this.map.put("version", stringBuilder.toString());
        this.map.put("deviceType", "2");
        this.map.put("token", AtmosPreference.getCustomAppProfile("token"));
        this.map.put("deviceId", getMac());
        this.map.put("channel", "Umeng");
        this.map.put("gpsCity", AtmosPreference.getCustomAppProfile("location_city"));
        this.map.put("timestamp", new BaseRequestWrapper("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis())));
    }

    public BaseRequestWrapper(String str) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(ApkManager.getVersionCode(Atmos.getApplicationContext()));
        stringBuilder.append("");
        this.map.put("version", stringBuilder.toString());
        this.map.put("deviceType", "2");
        this.map.put("token", str);
        this.map.put("deviceId", getMac());
        this.map.put("channel", "Umeng");
        this.map.put("gpsCity", AtmosPreference.getCustomAppProfile("location_city"));
        this.map.put("timestamp", new BaseRequestWrapper("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis())));
    }

    private String getMac() {
        return ApkUtil.getDeviceId();
    }

    public void put(String str, String str2) {
        this.map.put(str, str2);
    }

    public void put(WeakHashMap<String, Object> weakHashMap) {
        this.map.putAll(weakHashMap);
    }
}

package com.qsmx.qigyou.ec.httputil;

import android.text.TextUtils;
import com.qsmx.qigyou.app.Atmos;
import com.qsmx.qigyou.ec.util.ApkUtil;
import com.qsmx.qigyou.ec.util.Md5Util;
import com.qsmx.qigyou.manager.ApkManager;
import com.qsmx.qigyou.util.storage.AtmosPreference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.WeakHashMap;

public class BaseRequestWrapper {
    private WeakHashMap<String, Object> map = new WeakHashMap();

    public WeakHashMap<String, Object> sign() {
        ArrayList arrayList = new ArrayList();
        for (String add : this.map.keySet()) {
            arrayList.add(add);
        }
        String[] strArr = (String[]) arrayList.toArray(new String[arrayList.size()]);
        Arrays.sort(strArr);
        String str = "eaM3N_sUOqQn,A,q";
        for (Object obj : strArr) {
            if (!TextUtils.isEmpty((CharSequence) this.map.get(obj))) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(str);
                stringBuilder.append(obj);
                stringBuilder.append(this.map.get(obj));
                str = stringBuilder.toString();
            }
        }
        StringBuilder stringBuilder2 = new StringBuilder();
        stringBuilder2.append(str);
        stringBuilder2.append("eaM3N_sUOqQn,A,q");
        try {
            this.map.put("sign", Md5Util.md5(stringBuilder2.toString()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this.map;
    }

    public BaseRequestWrapper() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(ApkManager.getVersionCode(Atmos.getApplicationContext()));
        stringBuilder.append("");
        this.map.put("version", stringBuilder.toString());
        this.map.put("deviceType", "2");
        this.map.put("token", AtmosPreference.getCustomAppProfile("token"));
        this.map.put("deviceId", getMac());
        this.map.put("channel", "Umeng");
        this.map.put("gpsCity", AtmosPreference.getCustomAppProfile("location_city"));
        this.map.put("timestamp", new BaseRequestWrapper("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis())));
    }

    public BaseRequestWrapper(String str) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(ApkManager.getVersionCode(Atmos.getApplicationContext()));
        stringBuilder.append("");
        this.map.put("version", stringBuilder.toString());
        this.map.put("deviceType", "2");
        this.map.put("token", str);
        this.map.put("deviceId", getMac());
        this.map.put("channel", "Umeng");
        this.map.put("gpsCity", AtmosPreference.getCustomAppProfile("location_city"));
        this.map.put("timestamp", new BaseRequestWrapper("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis())));
    }

    private String getMac() {
        return ApkUtil.getDeviceId();
    }

    public void put(String str, String str2) {
        this.map.put(str, str2);
    }

    public void put(WeakHashMap<String, Object> weakHashMap) {
        this.map.putAll(weakHashMap);
    }
}

  • 写回答

3条回答 默认 最新

  • 关注

    这是用MD5加密的,首先把要发送的数据封装成键值对,然后进行MD5加密,把加密后的串当做参数一起发送。

    评论

报告相同问题?