请问各位大佬们 这个安卓应用 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);
    }
}

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

你这个加密算法,首先对map中所有的kv中的K进行排序。然后遍历整个map,进行拼接,str+k+v的进行,遍历结束之后在拼接一个str,最后对这个字符串取Md5码。因此取md5之前,得到的字符串是N个str+k+v最后+str

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps: 问答会员年卡【8折】购 ,限时加赠IT实体书,即可 享受50次 有问必答服务,了解详情>>>https://t.csdnimg.cn/RW5m